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
determine locales from dir
  • Loading branch information
michaelmcmillan committed Mar 29, 2020
commit f70d5a6583780b6ea644124dd8c18347abd862ee
15 changes: 13 additions & 2 deletions ops/lost-in-translation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { parse } = require('path');
const { readdirSync } = require('fs');
const { spawnSync } = require('child_process');

/**
Expand Down Expand Up @@ -46,6 +48,15 @@ function normalizeTranslationKey(translationKey) {
return translationKey.replace(/[\s\n\t]+/g, ' ').trim();
}

/**
* Find all the locales (ie. en-IN, no, se) in the provided directory.
*/
function retrieveAllLocales(directoryPath) {
const filenames = readdirSync(directoryPath);
const locales = filenames.map(filename => parse(filename).name);
return locales;
}

/**
* Step 1: Find all the (english) translation keys across all branches and PRs.
*
Expand All @@ -62,8 +73,8 @@ function normalizeTranslationKey(translationKey) {
* since the start of the project across all branches and PRs. We throw them into a set that
Copy link
Member

Choose a reason for hiding this comment

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

This sounds unnecessary to me, as it would also include WIP's and stale branches. But it might be some cases where this makes sense that I have not thought about?

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, that's the part that sucks, but having it would make sure that all translations are added and (hopefully) translated by the time we want to merge it.

Copy link
Member

Choose a reason for hiding this comment

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

Aha, I understand. So a possible solution would be to run this if this run as a cronjob or something, so that the sheet is updated as soon as there are new texts in the repo?

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, so in the case with Stano's PR, those translations are now added to the sheet (even though his PR is WIP). Not sure if we want that or not, but we could try it out?

* we use in the next step.
*/
allLocales = new Set(['no', 'se']);
allEnglishTranslationKeys = new Set([]);
const allLocales = retrieveAllLocales('app/locales/');
const allEnglishTranslationKeys = new Set([]);
for (const locale of allLocales) {
const filePath = `app/locales/${locale}.json`;
for (const commitHash of findCommitHashesForFile(filePath)) {
Expand Down