From 984378434bcf8f062142959a2897a9ce64744280 Mon Sep 17 00:00:00 2001 From: Maximilian Loy Date: Mon, 25 Jul 2016 17:25:35 +0200 Subject: [PATCH 1/3] Add Android support for localized resource strings starting with '_@' --- bin/lib/android.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bin/lib/android.js b/bin/lib/android.js index 05c6d18..a671c20 100644 --- a/bin/lib/android.js +++ b/bin/lib/android.js @@ -90,6 +90,7 @@ module.exports = function (context) { var newNode = new ET.SubElement(parent, config.tagname); newNode.attrib = config.attrs; + replaceI18n(newNode); if (config.strings) { console.log("will push strings array "+JSON.stringify(config.strings)); @@ -137,7 +138,7 @@ module.exports = function (context) { var titleItemXml = new ET.SubElement(titlesXml, "item"), valueItemXml = new ET.SubElement(valuesXml, "item"); - titleItemXml.text = stringsArray.titles[i]; + titleItemXml.text = replaceI18nString(stringsArray.titles[i]); valueItemXml.text = stringsArray.values[i]; } }); @@ -236,6 +237,22 @@ module.exports = function (context) { }); } + + function replaceI18nString(text) { + if(text.startsWith('_@')) { + text = '@string/' + text.slice(2, text.length); + } + return text; + } + + function replaceI18n(node) { + ['android:title', 'android:summary'].forEach(function (attribute) { + if(node.attrib[attribute]) { + node.attrib[attribute] = replaceI18nString(node.attrib[attribute]); + } + }); + } + return { mapConfig: mapConfig, buildSettings: buildSettings, From 27b36c9156128e1a5dc2ac66d9c8d66cce23dd27 Mon Sep 17 00:00:00 2001 From: Maximilian Loy Date: Mon, 25 Jul 2016 17:27:22 +0200 Subject: [PATCH 2/3] Also show description with 'toggle' preference --- bin/lib/mappings.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/lib/mappings.js b/bin/lib/mappings.js index e4b5924..eebb51a 100644 --- a/bin/lib/mappings.js +++ b/bin/lib/mappings.js @@ -4,7 +4,7 @@ * */ 'use strict'; - + var commonMappings = { title: { ios: "Title", @@ -90,6 +90,7 @@ module.exports = { key: commonMappings.key, title: commonMappings.title, default: commonMappings.default, + description: commonMappings.description, } }, textfield: { @@ -137,4 +138,4 @@ module.exports = { // 2. for a slider // 3. to simulate android summary for fields } -}; \ No newline at end of file +}; From b6118d7675a481174835cf29c45587deef4c7ab0 Mon Sep 17 00:00:00 2001 From: Maximilian Loy Date: Mon, 25 Jul 2016 22:13:43 +0200 Subject: [PATCH 3/3] Add iOS support for localized resource strings starting with '_@' --- bin/lib/android.js | 4 ++-- bin/lib/ios.js | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/bin/lib/android.js b/bin/lib/android.js index a671c20..2dc24a6 100644 --- a/bin/lib/android.js +++ b/bin/lib/android.js @@ -90,7 +90,7 @@ module.exports = function (context) { var newNode = new ET.SubElement(parent, config.tagname); newNode.attrib = config.attrs; - replaceI18n(newNode); + replaceI18nNode(newNode); if (config.strings) { console.log("will push strings array "+JSON.stringify(config.strings)); @@ -245,7 +245,7 @@ module.exports = function (context) { return text; } - function replaceI18n(node) { + function replaceI18nNode(node) { ['android:title', 'android:summary'].forEach(function (attribute) { if(node.attrib[attribute]) { node.attrib[attribute] = replaceI18nString(node.attrib[attribute]); diff --git a/bin/lib/ios.js b/bin/lib/ios.js index edf49ed..abdc48c 100644 --- a/bin/lib/ios.js +++ b/bin/lib/ios.js @@ -38,7 +38,7 @@ module.exports = function (Q, fs, path, plist, xcode) { throw "no mapping for type: "+ config.type + ", attr: " + attrName + ", value: " + config[attrName]; element[elementKey] = attrConfig.value[config[attrName]][platformName]; } else { - element[elementKey] = config[attrName]; + element[elementKey] = replaceI18nString(config[attrName]); } } } @@ -46,6 +46,11 @@ module.exports = function (Q, fs, path, plist, xcode) { if (mapping.fixup && mapping.fixup[platformName]) { mapping.fixup[platformName] (element, config, mapping); } + if (element['Titles']) { + element['Titles'].forEach(function(value, i) { + element['Titles'][i] = replaceI18nString(value); + }); + } return element; } @@ -107,7 +112,7 @@ module.exports = function (Q, fs, path, plist, xcode) { function build(config) { - var plistXml = plist.build({ PreferenceSpecifiers: buildItems(config) }); + var plistXml = plist.build({ PreferenceSpecifiers: buildItems(config), StringsTable: 'Root' }); return fs.exists('platforms/ios') // Check if Settings.bundle is generated by plugin @@ -129,8 +134,8 @@ module.exports = function (Q, fs, path, plist, xcode) { .then(function () {return fs.writeFile('platforms/ios/Settings.bundle/Root.plist', plistXml); }) // Write localization resource file - .then(function () {return fs.mkdir('platforms/ios/Settings.bundle/en.lproj'); }) - .then(function () {return fs.writeFile('platforms/ios/Settings.bundle/en.lproj/Root.strings', '/* */'); }) + // .then(function () {return fs.mkdir('platforms/ios/Settings.bundle/en.lproj'); }) + // .then(function () {return fs.writeFile('platforms/ios/Settings.bundle/en.lproj/Root.strings', '/* */'); }) // Add Settings plist to xcodeproj .then(buildXCode) @@ -184,6 +189,13 @@ module.exports = function (Q, fs, path, plist, xcode) { }); } + function replaceI18nString(text) { + if(text.startsWith && text.startsWith('_@')) { + text = text.slice(2, text.length); + } + return text; + } + return { mapConfig: mapConfig, buildItems: buildItems,