From 5ff5d0e28d2e35a68edbbde568c34e3caaab9c59 Mon Sep 17 00:00:00 2001 From: alexandercerutti Date: Sun, 12 Aug 2018 17:25:20 +0200 Subject: [PATCH] Added _generateStringFile method documentation; Changed checks to return an empty buffer; Added filter on inverted commas in content when pushing translation to avoid invalid .strings content --- index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 38a3637..5ca9482 100644 --- a/index.js +++ b/index.js @@ -135,12 +135,21 @@ class Pass { } } + /** + * Creates a buffer of translations in Apple .strings format + * + * @method _generateStringFile + * @params {String} lang - the ISO 3166 alpha-2 code for the language + * @returns {Buffer} - Buffer to be written in pass.strings for language in lang + * @see https://apple.co/2M9LWVu - String Resources + */ + _generateStringFile(lang) { - if (this.l10n[lang] === undefined || !Object.keys(this.l10n[lang]).length) { + if (!Object.keys(this.l10n[lang]).length) { return Buffer.from("", "utf8"); } - let strings = Object.keys(this.l10n[lang]).map(key => `"${key}" = "${this.l10n[lang][key]}";`); + let strings = Object.keys(this.l10n[lang]).map(key => `"${key}" = "${this.l10n[lang][key].replace(/"/g, /\\"/)}";`); return Buffer.from(strings.join("\n"), "utf8"); }