Skip to content

Commit c5fbd4b

Browse files
author
Nikos Vasileiou
authored
Merge pull request #136 from transifex/i18next-post-fixes
Fix plural handling in i18next backend
2 parents 8eb982a + 8485ca5 commit c5fbd4b

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

packages/i18next/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ npx txjs-cli push source.json --parser=i18next
9292

9393
That's it. Given that the content is translated, translations will be downloaded over-the-air using the Transifex i18next backend.
9494

95+
# Known limitations
96+
97+
CLI does NOT parse and push the following key types:
98+
- keyWithArrayValue
99+
- keyWithObjectValue
100+
95101
# License
96102

97103
Licensed under Apache License 2.0, see [LICENSE](https://github.com/transifex/transifex-javascript/blob/HEAD/LICENSE) file.

packages/i18next/src/TransifexI18next.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import { createNativeInstance, explodePlurals } from '@transifex/native';
22

33
export default class TransifexI18next {
4-
constructor(services, options) {
4+
constructor(options) {
55
this.type = 'backend';
6-
this.init(services, options);
6+
this.options = options || {};
7+
this.init();
78
}
89

910
init(services, backendOptions) {
10-
this.tx = createNativeInstance(backendOptions);
11+
this.options = {
12+
...(this.options || {}),
13+
...(backendOptions || {}),
14+
};
15+
this.tx = createNativeInstance(this.options);
1116
}
1217

1318
read(language, namespace, callback) {
@@ -47,7 +52,7 @@ export default class TransifexI18next {
4752
return;
4853
}
4954
const baseKey = key.slice(0, -('_txplural'.length));
50-
const plurals = explodePlurals(translations[key])[1];
55+
const plurals = explodePlurals(translations[key].replace('{???,', '{count,'))[1];
5156
Object.keys(plurals).forEach((plural) => {
5257
data[`${baseKey}_${plural}`] = plurals[plural];
5358
});

packages/i18next/webpack.browser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module.exports = {
2727
use: {
2828
loader: 'babel-loader',
2929
options: {
30+
sourceType: 'unambiguous',
3031
presets: ['@babel/preset-env'],
3132
plugins: [['@babel/transform-runtime']],
3233
},

0 commit comments

Comments
 (0)