Commit cd00499d authored by dschuyler's avatar dschuyler Committed by Commit Bot

[i18n] use Polymer data binding to change locale strings

This CL uses Polymer variable binding to swap out i18n strings rather
than using i18n-content.

BUG=692763
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2886843005
Cr-Commit-Position: refs/heads/master@{#476358}
parent 4dc3eafa
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
Polymer({ Polymer({
is: 'oobe-welcome-md', is: 'oobe-welcome-md',
behaviors: [I18nBehavior],
properties: { properties: {
/** /**
* Currently selected system language (display name). * Currently selected system language (display name).
...@@ -32,7 +34,7 @@ Polymer({ ...@@ -32,7 +34,7 @@ Polymer({
*/ */
languages: { languages: {
type: Array, type: Array,
observer: "onLanguagesChanged_", observer: 'onLanguagesChanged_',
}, },
/** /**
...@@ -41,7 +43,7 @@ Polymer({ ...@@ -41,7 +43,7 @@ Polymer({
*/ */
keyboards: { keyboards: {
type: Array, type: Array,
observer: "onKeyboardsChanged_", observer: 'onKeyboardsChanged_',
}, },
/** /**
...@@ -89,7 +91,7 @@ Polymer({ ...@@ -89,7 +91,7 @@ Polymer({
/** /**
* Controls displaying of "Enable debugging features" link. * Controls displaying of "Enable debugging features" link.
*/ */
debuggingLinkVisible: Boolean, debuggingLinkVisible: Boolean,
}, },
/** /**
...@@ -130,6 +132,8 @@ Polymer({ ...@@ -130,6 +132,8 @@ Polymer({
addWiFiNetworkMenuName: loadTimeData.getString('addWiFiNetworkMenuName'), addWiFiNetworkMenuName: loadTimeData.getString('addWiFiNetworkMenuName'),
proxySettingsMenuName: loadTimeData.getString('proxySettingsMenuName'), proxySettingsMenuName: loadTimeData.getString('proxySettingsMenuName'),
}; };
this.i18nUpdateLocale();
}, },
/** /**
...@@ -207,21 +211,27 @@ Polymer({ ...@@ -207,21 +211,27 @@ Polymer({
customItemName: 'proxySettingsMenuName', customItemName: 'proxySettingsMenuName',
polymerIcon: 'oobe-welcome-20:add-proxy', polymerIcon: 'oobe-welcome-20:add-proxy',
customData: { customData: {
onTap: function() { self.OpenProxySettingsDialog_(); }, onTap: function() {
self.OpenProxySettingsDialog_();
},
}, },
}, },
{ {
customItemName: 'addWiFiNetworkMenuName', customItemName: 'addWiFiNetworkMenuName',
polymerIcon: 'oobe-welcome-20:add-wifi', polymerIcon: 'oobe-welcome-20:add-wifi',
customData: { customData: {
onTap: function() { self.OpenAddWiFiNetworkDialog_(); }, onTap: function() {
self.OpenAddWiFiNetworkDialog_();
},
}, },
}, },
{ {
customItemName: 'addMobileNetworkMenuName', customItemName: 'addMobileNetworkMenuName',
polymerIcon: 'oobe-welcome-20:add-cellular', polymerIcon: 'oobe-welcome-20:add-cellular',
customData: { customData: {
onTap: function() { self.OpenAddWiFiNetworkDialog_(); }, onTap: function() {
self.OpenAddWiFiNetworkDialog_();
},
}, },
}, },
]; ];
...@@ -275,7 +285,7 @@ Polymer({ ...@@ -275,7 +285,7 @@ Polymer({
}, },
/** /**
* Handle Networwork Setup screen "Proxy settings" button. * Handle Network Setup screen "Proxy settings" button.
* *
* @private * @private
*/ */
...@@ -284,7 +294,7 @@ Polymer({ ...@@ -284,7 +294,7 @@ Polymer({
}, },
/** /**
* Handle Networwork Setup screen "Add WiFi network" button. * Handle Network Setup screen "Add WiFi network" button.
* *
* @private * @private
*/ */
...@@ -293,7 +303,7 @@ Polymer({ ...@@ -293,7 +303,7 @@ Polymer({
}, },
/** /**
* Handle Networwork Setup screen "Add cellular network" button. * Handle Network Setup screen "Add cellular network" button.
* *
* @private * @private
*/ */
......
...@@ -35,11 +35,17 @@ function testI18nAdvanced() { ...@@ -35,11 +35,17 @@ function testI18nAdvanced() {
I18nBehavior.i18nAdvanced('customTag', {tags: ['X-FOO']}); I18nBehavior.i18nAdvanced('customTag', {tags: ['X-FOO']});
} }
function testI18nDynamic() {
var locale = 'en';
assertEquals("I'm just text, nobody should have a problem with me!",
I18nBehavior.i18nDynamic(locale, 'text'));
}
function testI18nExists() { function testI18nExists() {
assertTrue(I18nBehavior.i18nExists('text')); assertTrue(I18nBehavior.i18nExists('text'));
assertFalse(I18nBehavior.i18nExists('missingText')); assertFalse(I18nBehavior.i18nExists('missingText'));
} }
</script> </script>
</body> </body>
</html> </html>
...@@ -4,17 +4,23 @@ ...@@ -4,17 +4,23 @@
/** /**
* @fileoverview * @fileoverview
* 'I18nBehavior' is a behavior to mix in loading of * 'I18nBehavior' is a behavior to mix in loading of internationalization
* internationalization strings. * strings.
*
* Example:
* behaviors: [
* I18nBehavior,
* ],
*/ */
/** @polymerBehavior */ /** @polymerBehavior */
var I18nBehavior = { var I18nBehavior = {
properties: {
/**
* The language the UI is presented in. Used to signal dynamic language
* change.
*/
locale: {
type: String,
value: '',
},
},
/** /**
* Returns a translated string where $1 to $9 are replaced by the given * Returns a translated string where $1 to $9 are replaced by the given
* values. * values.
...@@ -59,6 +65,19 @@ var I18nBehavior = { ...@@ -59,6 +65,19 @@ var I18nBehavior = {
.firstChild.innerHTML; .firstChild.innerHTML;
}, },
/**
* Similar to 'i18n', with an unused |locale| parameter used to trigger
* updates when |this.locale| changes.
* @param {string} locale The UI language used.
* @param {string} id The ID of the string to translate.
* @param {...string} var_args Values to replace the placeholders $1 to $9
* in the string.
* @return {string} A translated, sanitized, substituted string.
*/
i18nDynamic: function(locale, id, var_args) {
return this.i18n.apply(this, Array.prototype.slice.call(arguments, 1));
},
/** /**
* Returns true if a translation exists for |id|. * Returns true if a translation exists for |id|.
* @param {string} id * @param {string} id
...@@ -67,6 +86,14 @@ var I18nBehavior = { ...@@ -67,6 +86,14 @@ var I18nBehavior = {
i18nExists: function(id) { i18nExists: function(id) {
return loadTimeData.valueExists(id); return loadTimeData.valueExists(id);
}, },
/**
* Call this when UI strings may have changed. This will send an update to any
* data bindings to i18nDynamic(locale, ...).
*/
i18nUpdateLocale: function() {
this.locale = loadTimeData.getString('language');
},
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment