Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Sync missing translation keys in app/locales/*.json files to a Google Sheet #481

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
delimit language with ---
  • Loading branch information
michaelmcmillan committed Mar 29, 2020
commit 432870dcdd8a260e46dee5fb9819c0eba54edcbc
13 changes: 11 additions & 2 deletions ops/lost-in-translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ function retrieveJSONForFileAtCommitHash(filePath, commitHash) {
}
}

/**
* Normalizes translation key like we do in app/server.ts.
*/
function normalizeTranslationKey(translationKey) {
return translationKey.replace(/[\s\n\t]+/g, ' ').trim();
}

/**
* Step 1: Find all the (english) translation keys across all branches and PRs.
*
Expand All @@ -62,7 +69,7 @@ for (const locale of allLocales) {
for (const commitHash of findCommitHashesForFile(filePath)) {
const translation = retrieveJSONForFileAtCommitHash(filePath, commitHash);
for (const translationKey of Object.keys(translation)) {
allEnglishTranslationKeys.add(translationKey);
allEnglishTranslationKeys.add(normalizeTranslationKey(translationKey));
}
}
}
Expand All @@ -83,17 +90,19 @@ for (const locale of allLocales) {
const filePath = `app/locales/${locale}.json`;
for (const commitHash of findCommitHashesForFile(filePath)) {
const translation = retrieveJSONForFileAtCommitHash(filePath, commitHash);
const translationKeys = Object.keys(translation).map(key => normalizeTranslationKey(key));
if (translationKeysByLocale[locale] === undefined) {
translationKeysByLocale[locale] = new Set([]);
}
translationKeysByLocale[locale] = new Set([...translationKeysByLocale[locale], ...Object.keys(translation)]);
translationKeysByLocale[locale] = new Set([...translationKeysByLocale[locale], ...translationKeys]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel stuff like this is mentally much easier to visualize when translationKeysByLocale is typed :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we can tweak that, wanted to get it out quickly before bed

}
}

/**
* Step 3: Print out the missing keys for each locale.
*/
for (const locale of allLocales) {
console.log('---');
for (const englishTranslationKey of allEnglishTranslationKeys) {
if (!translationKeysByLocale[locale].has(englishTranslationKey)) {
console.log(locale, 'missing translation for:', englishTranslationKey);
Expand Down