Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: added simple check for formal language and fixes formal languge #983

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading