mirror of
https://github.com/SchildiChat/element-web.git
synced 2024-10-01 01:26:12 -04:00
Fix plurals in translations
See https://github.com/matrix-org/matrix-react-sdk/pull/1358 Requires https://github.com/matrix-org/matrix-react-sdk/pull/1358
This commit is contained in:
parent
ba2f7b78e8
commit
1e203cade7
@ -156,7 +156,7 @@ function genLangFile(lang, dest) {
|
||||
const reactSdkFile = 'node_modules/matrix-react-sdk/src/i18n/strings/' + lang + '.json';
|
||||
const riotWebFile = 'src/i18n/strings/' + lang + '.json';
|
||||
|
||||
const translations = {};
|
||||
let translations = {};
|
||||
[reactSdkFile, riotWebFile].forEach(function(f) {
|
||||
if (fs.existsSync(f)) {
|
||||
Object.assign(
|
||||
@ -165,6 +165,9 @@ function genLangFile(lang, dest) {
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
translations = weblateToCounterpart(translations)
|
||||
|
||||
fs.writeFileSync(dest + lang + '.json', JSON.stringify(translations, null, 4));
|
||||
if (verbose) {
|
||||
console.log("Generated language file: " + lang);
|
||||
@ -193,5 +196,39 @@ function genLangList() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert translation key from weblate format
|
||||
* (which only supports a single level) to counterpart
|
||||
* which requires object values for 'count' translations.
|
||||
*
|
||||
* eg.
|
||||
* "there are %(count)s badgers|one": "a badger",
|
||||
* "there are %(count)s badgers|other": "%(count)s badgers"
|
||||
* becomes
|
||||
* "there are %(count)s badgers": {
|
||||
* "one": "a badger",
|
||||
* "other": "%(count)s badgers"
|
||||
* }
|
||||
*/
|
||||
function weblateToCounterpart(inTrs) {
|
||||
const outTrs = {};
|
||||
|
||||
for (const key of Object.keys(inTrs)) {
|
||||
const keyParts = key.split('|', 2);
|
||||
if (keyParts.length === 2) {
|
||||
let obj = outTrs[keyParts[0]];
|
||||
if (obj === undefined) {
|
||||
obj = {};
|
||||
outTrs[keyParts[0]] = obj;
|
||||
}
|
||||
obj[keyParts[1]] = inTrs[key];
|
||||
} else {
|
||||
outTrs[key] = inTrs[key];
|
||||
}
|
||||
}
|
||||
|
||||
return outTrs;
|
||||
}
|
||||
|
||||
genLangList();
|
||||
next(0);
|
||||
|
Loading…
Reference in New Issue
Block a user