Skip to content

Commit

Permalink
Merge pull request #29 from ebidel/fix
Browse files Browse the repository at this point in the history
Fixes demo for removal of O.o()
  • Loading branch information
ebidel committed Dec 17, 2015
2 parents 287a3f1 + bf3d050 commit 17aa116
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"/tests/"
],
"dependencies": {
"polymer": "Polymer/polymer#^1.1.4",
"polymer": "Polymer/polymer#^1.2.3",
"observe-js": "Polymer/observe-js"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
// Event is only needed when running under the HTMLImports polyfill.
document.addEventListener('HTMLImportsLoaded', function() {
I18nMsg.lang = selector.value || document.documentElement.lang || 'en';
Platform.performMicrotaskCheckpoint();
});

selector.addEventListener('change', function() {
Expand Down
7 changes: 6 additions & 1 deletion i18n-msg.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
document.addEventListener('HTMLImportsLoaded', function() {
I18nMsg.lang = 'es';
// I18nMsg.url = 'locales'; // optionally use custom folder for locales.
Platform.performMicrotaskCheckpoint();
});
<b>Note:</b> this is done in `HTMLImportsLoaded` so `I18nMsg` will be defined by
the time you set `I18nMsg.lang`. This timing is necessary under the polyfill and is
<b>not needed if the browser supports HTML Imports</b>, natively.
<b>Note:</b> you must call `Platform.performMicrotaskCheckpoint()` whenever
making a change to the `I18nMsg` object. This is required due to the removal
of `Object.observe()`.
### Message files
Setting a language instructs `<i18n-msg>` to read message ids from a predefined
Expand Down Expand Up @@ -254,7 +259,7 @@

_notifyInstances: function() {
for (var i = 0, instance; instance = _instances[i]; ++i) {
instance.language = I18nMsg.lang;
instance._setLanguage(I18nMsg.lang);

if (!instance.locales[instance.language][instance.msgid]) {
console.warn(this.localName + ': "' + instance.msgid + '" message id was not found');
Expand Down
6 changes: 6 additions & 0 deletions test/basic-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
assert.equal(el.language, I18nMsg.lang);
});

test('.language property is readOnly', function() {
var val = 'bogus';
el.language = val;
assert.notEqual(el.language, val);
});

test('.textContent was updated to localize message', function() {
assert.equal(el.textContent, expected);
});
Expand Down

0 comments on commit 17aa116

Please sign in to comment.