From a12eb03ce5e98801b0aac8909d082f4e584049a5 Mon Sep 17 00:00:00 2001 From: Yaroslav Nazarov Date: Fri, 29 Apr 2016 12:44:04 +1000 Subject: [PATCH] fix #315: macPlistStrings added to config --- README.md | 6 ++++++ lib/index.js | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/README.md b/README.md index fa4dba80c..ddf91d104 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,12 @@ Default value: `false` MAC ONLY: Pass a string containing the path to your own plist file. If a string isn't passed, a plist file will be generated from your package.json. Pass an object to overwrite or add properties to the generated plist file. +#### options.macPlistStrings +Type: `Object` +Default value: `{}` + +MAC ONLY: Pass an object where keys are laungauge abbreviations and values are the strings containing path to the localization file. If passed, these files will replace plistInfo.strings files for each passed language. + #### options.winIco Type: `String` Default value: `null` diff --git a/lib/index.js b/lib/index.js index 369b90ace..7e482968c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -39,6 +39,7 @@ function NwBuilder(options) { macZip: null, zip: null, macPlist: false, + macPlistStrings: {}, winIco: null, argv: process.argv.slice(2) }; @@ -549,6 +550,27 @@ NwBuilder.prototype.handleMacApp = function () { allDone.push(Utils.editPlist(PlistPath, PlistPath, plistOptions)); } + + // Let's handle Plist localization files + for (l18n in self.options.macPlistStrings) { + // Plist localization name and value should be strings + if (typeof l18n === 'string') { + if (typeof self.options.macPlistStrings[l18n] === 'string') { + var l18lFolder = path.resolve(platform.releasePath, self.options.appName+'.app', 'Contents', 'Resources', l18n+'.lproj'); + // The folder may not exist + if (!fs.existsSync(l18lFolder)) { + fs.mkdirSync(l18lFolder); + } + + var l18lpath = path.resolve(l18lFolder, 'InfoPlist.strings'); + allDone.push(Utils.copyFile(self.options.macPlistStrings[l18n], l18lpath, self)); + } else { + reject('Path to the localization file is not a string'); + } + } else { + reject('Name of the localization is not a string'); + } + } }); return Promise.all(allDone);