From 88f845cc69b1db04f00d0b8feb4d8fd375c5ab2b Mon Sep 17 00:00:00 2001 From: alexandercerutti Date: Sat, 11 Aug 2018 18:19:38 +0200 Subject: [PATCH] Added localize method to register translation in the class; Added _generateStringFile method to create pass.string Buffer --- index.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 6a58f99..7265333 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,7 @@ class Pass { this.overrides = this.options.overrides || {}; this.Certificates = {}; this.model = ""; + this.l10n = {}; } /** @@ -50,7 +51,7 @@ class Pass { let bundle = noDynList.filter(f => !f.includes(".lproj")); // 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 = (() => { 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