Refactored l10n bundles generation in .generate()

This commit is contained in:
Alexander Cerutti
2021-06-18 00:09:08 +02:00
parent eb36db44bb
commit 202e227b3d

View File

@@ -200,9 +200,15 @@ export class Pass {
* Iterating through languages and generating pass.string file * Iterating through languages and generating pass.string file
*/ */
Object.keys(this.l10nTranslations).forEach((lang) => { const translationsLanguageCodes = Object.keys(this.l10nTranslations);
for (
let langs = translationsLanguageCodes.length, lang: string;
(lang = translationsLanguageCodes[--langs]);
) {
const strings = generateStringFile(this.l10nTranslations[lang]); const strings = generateStringFile(this.l10nTranslations[lang]);
const langInBundles = `${lang}.lproj`; const languageBundleDirname = `${lang}.lproj`;
if (strings.length) { if (strings.length) {
/** /**
@@ -211,14 +217,14 @@ export class Pass {
* it otherwise. * it otherwise.
*/ */
if (!this.l10nBundles[langInBundles]) { if (!this.l10nBundles[languageBundleDirname]) {
this.l10nBundles[langInBundles] = {}; this.l10nBundles[languageBundleDirname] = {};
} }
this.l10nBundles[langInBundles][ this.l10nBundles[languageBundleDirname][
"pass.strings" "pass.strings"
] = Buffer.concat([ ] = Buffer.concat([
this.l10nBundles[langInBundles]["pass.strings"] || this.l10nBundles[languageBundleDirname]["pass.strings"] ||
Buffer.alloc(0), Buffer.alloc(0),
strings, strings,
]); ]);
@@ -226,8 +232,8 @@ export class Pass {
if ( if (
!( !(
this.l10nBundles[langInBundles] && this.l10nBundles[languageBundleDirname] &&
Object.keys(this.l10nBundles[langInBundles]).length Object.keys(this.l10nBundles[languageBundleDirname]).length
) )
) { ) {
return; return;
@@ -241,22 +247,21 @@ export class Pass {
* composition. * composition.
*/ */
Object.assign( const bundleRelativeL10NPaths = Object.entries(
finalBundle, this.l10nBundles[languageBundleDirname],
...Object.keys(this.l10nBundles[langInBundles]).map( ).reduce((acc, [fileName, fileContent]) => {
(fileName) => {
const fullPath = path const fullPath = path
.join(langInBundles, fileName) .join(languageBundleDirname, fileName)
.replace(/\\/, "/"); .replace(/\\/, "/");
return { return {
[fullPath]: this.l10nBundles[langInBundles][ ...acc,
fileName [fullPath]: fileContent,
],
}; };
}, }, {});
),
); Object.assign(finalBundle, bundleRelativeL10NPaths);
}); }
/* /*
* Parsing the buffers, pushing them into the archive * Parsing the buffers, pushing them into the archive
@@ -682,6 +687,7 @@ export class Pass {
"foregroundColor", "foregroundColor",
"labelColor", "labelColor",
] as Array<keyof Schemas.PassColors>; ] as Array<keyof Schemas.PassColors>;
passColors passColors
.filter( .filter(
(v) => (v) =>