Skip to content

remove untranslated base translations

Valentyne Stigloher requested to merge check-base-translations-in-locales into main

supported by following script:

import { loadSumlFromBase } from './loader.ts';
import { deepGet, deepListKeys } from '../src/helpers.ts';
import type { Translations } from '~/locale/translations.ts';

const baseTranslations = loadSumlFromBase('locale/_base/translations') as Translations;

const ignoredKeys = new Set([
    'title',
    'people',
    'english.header',
    'english.headerLong',
    'contact.groups.all',
    'contact.team.extra',
    'quotation.start',
    'quotation.end',
    'quotation.colon',
]);

const checkTranslations = (locale: string): void => {
    const translations = loadSumlFromBase(`locale/${locale}/translations`) as Translations;

    for (const key of deepListKeys(translations)) {
        const baseTranslation = JSON.stringify(deepGet(baseTranslations, key));
        const translation = JSON.stringify(deepGet(translations, key));
        if (!ignoredKeys.has(key) && !key.startsWith('faq') && baseTranslation && baseTranslation === translation) {
            process.stdout.write(`${key}\n    ${translation}\n`);
        }
    }
};

for (const locale of process.argv[2].split(',')) {
    checkTranslations(locale);
}

notes

  • by no means this approach can catch all untranslated terms: some nouns are really the same in English and other languages, so I can’t just remove all detected duplicates
  • I left faq alone because I believe it is ignored by missingTranslations.ts so we’d need to talk to contributors in those cases
  • there are also sometimes lots of # TODO which I sometimes removed when those would be visible via missingsTranslations.ts, othertimes I left them and we should also talk to contributors
  • there are some instances where the untranslated value was touched because the link checks suggested to insert the translated route (e.g. in zh) – I still removed it so it gets translated, but this introduces possible 404 links
  • also, sv looks like it has translated the route in calendar events, but not the values itself – prop talk to contributors

review questions

  • because this is sometimes a monotonous task: can I ask someone to go through the diff and re-check that only English-looking stuff is removed? better to double check when removing so much, I guess 😊
Edited by Valentyne Stigloher

Merge request reports