Skip to content

Commit

Permalink
feat: upgrade i18next dependency
Browse files Browse the repository at this point in the history
based on #48

Signed-off-by: Patrik Kullman <patrik.kullman@neovici.se>
  • Loading branch information
Patrik Kullman authored and cristinecula committed Apr 4, 2020
1 parent 37bea70 commit f07b598
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
22 changes: 13 additions & 9 deletions cosmoz-i18next.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PolymerElement } from '@polymer/polymer/polymer-element';
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin';
import 'i18next-client';
import i18n from 'i18next';

const { i18n } = window,
const
translationElements = [],
ensureInitialized = () => {
if (!i18n.isInitialized()) {
if (!i18n.isInitialized) {
// default i18n init, to ensure translate function will return something
// even when there is no <i18next> element in the page.
i18n.init({
Expand Down Expand Up @@ -45,9 +45,10 @@ const { i18n } = window,

delete args.count;

if (i18n.pluralExtensions.needsPlural(i18n.lng(), n)) {
const pluralSuffix = i18n.services.pluralResolver.getSuffix(i18n.language, n);
if (pluralSuffix) {
args.defaultValue = plural;
key = i18n.options.ns.defaultNs + i18n.options.nsseparator + singular + i18n.options.pluralSuffix;
key = singular + pluralSuffix;
} else {
key = singular;
args.defaultValue = singular;
Expand All @@ -73,9 +74,10 @@ const { i18n } = window,

delete args.count;

if (i18n.pluralExtensions.needsPlural(i18n.lng(), n)) {
const pluralSuffix = i18n.services.pluralResolver.getSuffix(i18n.language, n);
if (pluralSuffix) {
args.defaultValue = plural;
key = i18n.options.ns.defaultNs + i18n.options.nsseparator + singular + contextKeyPart + i18n.options.pluralSuffix;
key = singular + contextKeyPart + pluralSuffix;
} else {
key = singular;
args.context = context;
Expand Down Expand Up @@ -272,8 +274,10 @@ class CosmozI18Next extends PolymerElement {
}
ready() {
i18n.init({
interpolationPrefix: this.interpolationPrefix,
interpolationSuffix: this.interpolationSuffix,
interpolation: {
prefix: this.interpolationPrefix,
suffix: this.interpolationSuffix
},
keyseparator: this.keySeparator,
lng: this.language,
nsseparator: this.nsSeparator,
Expand Down
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
"dependencies": {
"@polymer/polymer": "^3.3.1",
"i18next-client": "^1.11.4"
"i18next": "^19.3.4"
},
"devDependencies": {
"@commitlint/cli": "^8.3.5",
Expand Down
10 changes: 6 additions & 4 deletions test/basic.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global i18n*/
import i18n from 'i18next';
import {
assert, fixture, html
} from '@open-wc/testing';
Expand Down Expand Up @@ -34,15 +34,17 @@ suite('core', () => {
const lng = 'sv',
translations = await fetch('/base/test/translations.json').then(r => r.json());
await i18n.init({
interpolationPrefix: '{',
interpolationSuffix: '}',
interpolation: {
prefix: '{',
suffix: '}'
},
lng
});
loadTranslations(lng, 'translation', translations);
});

test('init', () => {
assert.isTrue(window.i18n.isInitialized());
assert.isTrue(i18n.isInitialized);
});

test('_', () => {
Expand Down

0 comments on commit f07b598

Please # to comment.