Skip to content

Commit

Permalink
fix: fix ready, add translation loading tests
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Kullman <patrik.kullman@neovici.se>
  • Loading branch information
Patrik Kullman authored and cristinecula committed Apr 9, 2020
1 parent 1ef7dd2 commit e9f2c92
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions cosmoz-i18next.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class CosmozI18Next extends PolymerElement {
};
}
ready() {
super.ready();
i18n.init({
interpolation: {
prefix: this.interpolationPrefix,
Expand Down
29 changes: 25 additions & 4 deletions test/basic.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import i18n from 'i18next';
import {
assert, fixture, html
assert, fixture, html, aTimeout
} from '@open-wc/testing';

import {
Expand All @@ -26,21 +26,34 @@ suite('cosmoz-i18next', () => {
assert.equal(element.keySeparator, '.');
assert.equal(element.nsSeparator, ':');
});

test('set translations', async () => {
assert.equal(_('Hello __0__', 'John Doe'), 'Hello John Doe');
element.translations = {
'Hello __0__': 'Hej __0__'
};
await aTimeout();
assert.equal(_('Hello __0__', 'John Doe'), 'Hej John Doe');
element.translations = null; // doesn't throw away translations
assert.equal(_('Hello __0__', 'John Doe'), 'Hej John Doe');
});
});

suite('core', () => {

const lng = 'sv',
namespace = 'translation';

suiteSetup(async () => {
const lng = 'sv',
translations = await fetch('/base/test/translations.json').then(r => r.json());
const translations = await fetch('/base/test/translations.json').then(r => r.json());
await i18n.init({
interpolation: {
prefix: '{',
suffix: '}'
},
lng
});
loadTranslations(lng, 'translation', translations);
loadTranslations(lng, namespace, translations);
});

test('init', () => {
Expand Down Expand Up @@ -74,6 +87,14 @@ suite('core', () => {
assert.equal(npgettext('supplier', 'Cancel {0} invoice', 'Cancel {0} invoices', 1), 'Makulera en leverantörsfaktura');
assert.equal(npgettext('supplier', 'Cancel {0} invoice', 'Cancel {0} invoices', 2), 'Makulera 2 leverantörsfakturor');
});

test('update translations', () => {
loadTranslations(lng, namespace, {
'Cancel {0} invoice': 'Cancelar {0} factura'
});
assert.equal(_('Cancel {0} invoice', 1), 'Cancelar 1 factura');
assert.equal(npgettext('supplier', 'Cancel {0} invoice', 'Cancel {0} invoices', 2), 'Cancel 2 invoices');
});
});

suite('cosmoz-t', () => {
Expand Down

0 comments on commit e9f2c92

Please # to comment.