Skip to content

Commit

Permalink
minor fixes to binding
Browse files Browse the repository at this point in the history
  • Loading branch information
jamuhl committed Sep 11, 2018
1 parent cb237cb commit 0f2a0c9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 0.0.3

- check if bundle exists before getMessage call

### 0.0.2

- support accessing attributes on fluent segment using keys like `login.placeholder`
Expand Down
6 changes: 4 additions & 2 deletions i18nextFluent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2139,7 +2139,7 @@
}

bind() {
this.i18next.on('added', (lng, ns) => {
this.i18next.store.on('added', (lng, ns) => {
if (!this.i18next.isInitialized) return;
this.createBundleFromI18next(lng, ns);
});
Expand Down Expand Up @@ -2179,12 +2179,14 @@
const isAttr = key.indexOf('.') > -1;
if (!res) return key;
const useRes = isAttr ? res.attrs[key.split('.')[1]] : res;
if (!bundle) return key;
return bundle.format(useRes, options);
}

getResource(lng, ns, key, options) {
const bundle = this.store.getBundle(lng, ns);
let bundle = this.store.getBundle(lng, ns);
const useKey = key.indexOf('.') > -1 ? key.split('.')[0] : key;
if (!bundle) return key;
return bundle.getMessage(useKey);
}

Expand Down
2 changes: 1 addition & 1 deletion i18nextFluent.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "i18next-fluent",
"version": "0.0.2",
"version": "0.0.3",
"description": "i18nFormat plugin to use fluent format with i18next",
"main": "./index.js",
"jsnext:main": "dist/es/index.js",
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class BundleStore {
}

bind() {
this.i18next.on('added', (lng, ns) => {
this.i18next.store.on('added', (lng, ns) => {
if (!this.i18next.isInitialized) return;
this.createBundleFromI18next(lng, ns);
});
Expand Down Expand Up @@ -101,13 +101,15 @@ class Fluent {
if (!res) return key;

const useRes = isAttr ? res.attrs[key.split('.')[1]] : res;
if (!bundle) return key;
return bundle.format(useRes, options);
}

getResource(lng, ns, key, options) {
const bundle = this.store.getBundle(lng, ns);
let bundle = this.store.getBundle(lng, ns);
const useKey = key.indexOf('.') > -1 ? key.split('.')[0] : key;

if (!bundle) return key;
return bundle.getMessage(useKey);
}

Expand Down

0 comments on commit 0f2a0c9

Please sign in to comment.