Added localize method to register translation in the class; Added _generateStringFile method to create pass.string Buffer

This commit is contained in:
alexandercerutti
2018-08-11 18:19:38 +02:00
parent 89a21f47a0
commit 88f845cc69

View File

@@ -17,6 +17,7 @@ class Pass {
this.overrides = this.options.overrides || {}; this.overrides = this.options.overrides || {};
this.Certificates = {}; this.Certificates = {};
this.model = ""; this.model = "";
this.l10n = {};
} }
/** /**
@@ -50,7 +51,7 @@ class Pass {
let bundle = noDynList.filter(f => !f.includes(".lproj")); let bundle = noDynList.filter(f => !f.includes(".lproj"));
// Localization folders only // Localization folders only
const L10N = noDynList.filter(f => f.includes(".lproj")); const L10N = noDynList.filter(f => f.includes(".lproj") && Object.keys(this.l10n).includes(path.parse(f).name));
let _passExtractor = (() => { let _passExtractor = (() => {
return readFile(path.resolve(this.model, "pass.json")) return readFile(path.resolve(this.model, "pass.json"))
@@ -107,6 +108,23 @@ class Pass {
}); });
} }
/*
*/
localize(lang, translations) {
this.l10n[lang] = translations;
}
_generateStringFile(lang) {
if (this.l10n[lang] === undefined || !Object.keys(this.l10n[lang]).length) {
return Buffer.from("", "utf8");
}
let strings = Object.keys(this.l10n[lang]).map(key => `"${key}" = "${this.l10n[lang][key]}";`);
return Buffer.from(strings.join("\n"), "utf8");
}
/** /**
Checks if pass model type is one of the supported ones Checks if pass model type is one of the supported ones