mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 18:25:24 +00:00
Refactored l10n bundles generation in .generate()
This commit is contained in:
54
src/pass.ts
54
src/pass.ts
@@ -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(languageBundleDirname, fileName)
|
||||||
.join(langInBundles, 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) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user