Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localization support #104

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion bin/lib/android.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ module.exports = function (context) {

var newNode = new ET.SubElement(parent, config.tagname);
newNode.attrib = config.attrs;
replaceI18nNode(newNode);

if (config.strings) {
console.log("will push strings array "+JSON.stringify(config.strings));
Expand Down Expand Up @@ -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];
}
});
Expand Down Expand Up @@ -236,6 +237,22 @@ module.exports = function (context) {
});
}


function replaceI18nString(text) {
if(text.startsWith('_@')) {
text = '@string/' + text.slice(2, text.length);
}
return text;
}

function replaceI18nNode(node) {
['android:title', 'android:summary'].forEach(function (attribute) {
if(node.attrib[attribute]) {
node.attrib[attribute] = replaceI18nString(node.attrib[attribute]);
}
});
}

return {
mapConfig: mapConfig,
buildSettings: buildSettings,
Expand Down
20 changes: 16 additions & 4 deletions bin/lib/ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,19 @@ 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]);
}
}
}

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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions bin/lib/mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
*/
'use strict';

var commonMappings = {
title: {
ios: "Title",
Expand Down Expand Up @@ -90,6 +90,7 @@ module.exports = {
key: commonMappings.key,
title: commonMappings.title,
default: commonMappings.default,
description: commonMappings.description,
}
},
textfield: {
Expand Down Expand Up @@ -137,4 +138,4 @@ module.exports = {
// 2. for a slider
// 3. to simulate android summary for fields
}
};
};