mirror of https://github.com/vector-im/riot-web
Get English plural strings from an input file
parent
f5a4dcd201
commit
f759467193
|
@ -32,10 +32,7 @@ const estreeWalker = require('estree-walker');
|
||||||
|
|
||||||
const TRANSLATIONS_FUNCS = ['_t', '_td', '_tJsx'];
|
const TRANSLATIONS_FUNCS = ['_t', '_td', '_tJsx'];
|
||||||
|
|
||||||
// A selection of plural variants to put in the base file: other langauges
|
const INPUT_TRANSLATIONS_FILE = 'src/i18n/strings/en_EN.json';
|
||||||
// with more types of plural will have more, but they will just be in the file
|
|
||||||
// for that language.
|
|
||||||
const COUNTSTRINGS = ['one', 'other'];
|
|
||||||
|
|
||||||
const FLOW_PARSER_OPTS = {
|
const FLOW_PARSER_OPTS = {
|
||||||
esproposal_class_instance_fields: true,
|
esproposal_class_instance_fields: true,
|
||||||
|
@ -91,8 +88,12 @@ function getTranslations(file) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPlural) {
|
if (isPlural) {
|
||||||
for (const s of COUNTSTRINGS) {
|
trs.add(tKey + "|other");
|
||||||
trs.add(tKey + "|" + s);
|
const plurals = enPlurals[tKey];
|
||||||
|
if (plurals) {
|
||||||
|
for (const pluralType of Object.keys(plurals)) {
|
||||||
|
trs.add(tKey + "|" + pluralType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
trs.add(tKey);
|
trs.add(tKey);
|
||||||
|
@ -104,6 +105,21 @@ function getTranslations(file) {
|
||||||
return trs;
|
return trs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// gather en_EN plural strings from the input translations file:
|
||||||
|
// the en_EN strings are all in the source with the exception of
|
||||||
|
// pluralised strings, which we need to pull in from elsewhere.
|
||||||
|
const inputTranslationsRaw = JSON.parse(fs.readFileSync(INPUT_TRANSLATIONS_FILE, { encoding: 'utf8' }));
|
||||||
|
const enPlurals = {};
|
||||||
|
|
||||||
|
for (const key of Object.keys(inputTranslationsRaw)) {
|
||||||
|
const parts = key.split("|");
|
||||||
|
if (parts.length > 1) {
|
||||||
|
const plurals = enPlurals[parts[0]] || {};
|
||||||
|
plurals[parts[1]] = inputTranslationsRaw[key];
|
||||||
|
enPlurals[parts[0]] = plurals;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const translatables = new Set();
|
const translatables = new Set();
|
||||||
|
|
||||||
walk.walkSync("src", {
|
walk.walkSync("src", {
|
||||||
|
@ -124,6 +140,9 @@ walk.walkSync("src", {
|
||||||
const trObj = {};
|
const trObj = {};
|
||||||
for (const tr of translatables) {
|
for (const tr of translatables) {
|
||||||
trObj[tr] = tr;
|
trObj[tr] = tr;
|
||||||
|
if (tr.includes("|")) {
|
||||||
|
trObj[tr] = inputTranslationsRaw[tr];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
|
|
Loading…
Reference in New Issue