Skip to content

Commit

Permalink
Tools: Fixed missing translations when running build-translation tool
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Nov 9, 2021
1 parent 3782255 commit 33be306
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions packages/tools/build-translation.js
Expand Up @@ -29,22 +29,29 @@ function parsePoFile(filePath) {

function serializeTranslation(translation) {
const output = {};
const translations = translation.translations[''];
for (const n in translations) {
if (!translations.hasOwnProperty(n)) continue;
if (n == '') continue;
const t = translations[n];
let translated = '';
if (t.comments && t.comments.flag && t.comments.flag.indexOf('fuzzy') >= 0) {
// Don't include fuzzy translations
} else {
translated = t['msgstr'][0];
}

if (translated) output[n] = translated;
// Translations are grouped by "msgctxt"

for (const msgctxt of Object.keys(translation.translations)) {
const translations = translation.translations[msgctxt];

for (const n in translations) {
if (!translations.hasOwnProperty(n)) continue;
if (n == '') continue;
const t = translations[n];
let translated = '';
if (t.comments && t.comments.flag && t.comments.flag.indexOf('fuzzy') >= 0) {
// Don't include fuzzy translations
} else {
translated = t['msgstr'][0];
}

if (translated) output[n] = translated;
}
}

return JSON.stringify(output);
// Sort the translations to make the diff easier to read.
return JSON.stringify(output, Object.keys(output).sort((a, b) => a.toLowerCase() < b.toLowerCase() ? -1 : +1), ' ');
}

function saveToFile(filePath, data) {
Expand Down

0 comments on commit 33be306

Please sign in to comment.