Skip to content

Commit

Permalink
Merge pull request #983 from Onlineberatung/OB-7098
Browse files Browse the repository at this point in the history
chore: added simple check for formal language and fixes formal languge
  • Loading branch information
web-mi authored Nov 30, 2023
2 parents 4477063 + 7f1ca5f commit 6958266
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 44 deletions.
52 changes: 40 additions & 12 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,57 @@ export const init = (config: InitOptions) => {
return;
}

const deLanguage = [
...Object.keys(
flatten(i18n.getDataByLanguage(FALLBACK_LNG).common)
)
].sort();
const deLanguage: { [key: string]: string } = flatten(
i18n.getDataByLanguage(FALLBACK_LNG).common
);
const deLanguageKeys = [...Object.keys(deLanguage)].sort(
(a, b) => a.localeCompare(b)
);

const languages = Object.keys(
i18n.services.resourceStore.data
).filter((lng) => lng !== FALLBACK_LNG);

languages.forEach((lng) => {
const currLanguage = [
...Object.keys(
flatten(i18n.getDataByLanguage(lng).common)
)
].sort();
const missingKeys = _.xor(deLanguage, currLanguage);
const currLanguage: { [key: string]: string } = flatten(
i18n.getDataByLanguage(lng).common
);
const currLanguageKeys = [
...Object.keys(currLanguage)
].sort((a, b) => a.localeCompare(b));

if (lng.indexOf('_informal') >= 0) {
Object.entries({
...deLanguage,
...currLanguage
}).forEach(([key, text]) => {
const formalIndex = text.match(
/( Sie|Sie | Ihr|Ihr )/i
);
if (!formalIndex) return;

if (currLanguageKeys.includes(key)) {
console.error(
`[${lng}] has formal language sentence in key "${key}" near "${text.substring(
formalIndex.index - 25,
formalIndex.index + 25
)}"`
);
return;
}
console.error(
`[${lng}] has no formal language form for key "${key}" ("${text}")`
);
});
}

const missingKeys = _.xor(deLanguageKeys, currLanguageKeys);
if (missingKeys.length <= 0) {
return;
}

missingKeys.forEach((missingKey) => {
if (!deLanguage.includes(missingKey)) {
if (!deLanguageKeys.includes(missingKey)) {
console.error(
`[${lng}] has key "${missingKey}" but its missing in fallback language "${FALLBACK_LNG}"`
);
Expand Down
Loading

0 comments on commit 6958266

Please sign in to comment.