@transifex/i18next 4.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -0
- package/dist/browser.i18next.js +2 -0
- package/dist/browser.i18next.js.map +1 -0
- package/dist/node.i18next.d.ts +3 -0
- package/dist/node.i18next.js +2 -0
- package/dist/node.i18next.js.map +1 -0
- package/package.json +59 -0
- package/src/TransifexI18next.js +57 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +4 -0
- package/webpack.browser.js +37 -0
- package/webpack.config.js +7 -0
- package/webpack.node.js +25 -0
- package/webpack.test.js +21 -0
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@transifex/i18next",
|
|
3
|
+
"version": "4.1.0-alpha.0",
|
|
4
|
+
"description": "i18next backend plugin for Transifex Native",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"i18next",
|
|
7
|
+
"transifex",
|
|
8
|
+
"i18n",
|
|
9
|
+
"l10n",
|
|
10
|
+
"localization",
|
|
11
|
+
"internationalization",
|
|
12
|
+
"globalization",
|
|
13
|
+
"translation"
|
|
14
|
+
],
|
|
15
|
+
"author": "Transifex",
|
|
16
|
+
"homepage": "https://github.com/transifex/transifex-javascript/tree/master/packages/i18next",
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"main": "dist/node.i18next.js",
|
|
19
|
+
"browser": "dist/browser.i18next.js",
|
|
20
|
+
"types": "dist/node.i18next.d.ts",
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"repository": "git://github.com/transifex/transifex-javascript.git",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"lint": "eslint src/ tests/",
|
|
27
|
+
"build": "NODE_ENV=production webpack --config ./webpack.config.js && cp src/index.d.ts dist/node.i18next.d.ts",
|
|
28
|
+
"test": "NODE_ENV=test webpack --config webpack.test.js && nyc --reporter=text mocha --exit dist/test.i18next.js --require source-map-support/register && rm -f ./dist/test.*",
|
|
29
|
+
"publish-npm": "npm publish"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/transifex/transifex-javascript/issues"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=14.0.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@babel/core": "^7.17.10",
|
|
39
|
+
"@babel/plugin-transform-runtime": "^7.17.10",
|
|
40
|
+
"@babel/preset-env": "^7.17.10",
|
|
41
|
+
"@babel/runtime": "^7.17.8",
|
|
42
|
+
"babel-loader": "^8.1.0",
|
|
43
|
+
"chai": "^4.3.4",
|
|
44
|
+
"eslint": "^7.28.0",
|
|
45
|
+
"eslint-config-airbnb-base": "^14.2.0",
|
|
46
|
+
"eslint-plugin-import": "^2.23.4",
|
|
47
|
+
"glob": "^8.0.1",
|
|
48
|
+
"i18next": "^21.6.16",
|
|
49
|
+
"mocha": "^10.0.0",
|
|
50
|
+
"nock": "^13.2.4",
|
|
51
|
+
"nyc": "^15.1.0",
|
|
52
|
+
"source-map-support": "^0.5.19",
|
|
53
|
+
"webpack": "^5.72.0",
|
|
54
|
+
"webpack-cli": "^4.9.2"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@transifex/native": "^4.1.0-alpha.0"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createNativeInstance, explodePlurals } from '@transifex/native';
|
|
2
|
+
|
|
3
|
+
export default class TransifexI18next {
|
|
4
|
+
constructor(services, options) {
|
|
5
|
+
this.type = 'backend';
|
|
6
|
+
this.init(services, options);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
init(services, backendOptions) {
|
|
10
|
+
this.tx = createNativeInstance(backendOptions);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
read(language, namespace, callback) {
|
|
14
|
+
this.tx.fetchTranslations(language).then(() => {
|
|
15
|
+
callback(null,
|
|
16
|
+
this._convertPlurals(this.tx.cache.getTranslations(language)));
|
|
17
|
+
}).catch((err) => {
|
|
18
|
+
callback(err, null);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
readMulti(languages, namespaces, callback) {
|
|
23
|
+
const promises = [];
|
|
24
|
+
languages.forEach((language) => {
|
|
25
|
+
promises.push(this.tx.fetchTranslations(language));
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
Promise.all(promises).then(() => {
|
|
29
|
+
const data = {};
|
|
30
|
+
languages.forEach((language) => {
|
|
31
|
+
data[language] = {
|
|
32
|
+
translations:
|
|
33
|
+
this._convertPlurals(this.tx.cache.getTranslations(language)),
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
}).catch((err) => {
|
|
37
|
+
callback(err, null);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// eslint-disable-next-line class-methods-use-this
|
|
42
|
+
_convertPlurals(translations) {
|
|
43
|
+
const data = {};
|
|
44
|
+
Object.keys(translations).forEach((key) => {
|
|
45
|
+
if (!key.endsWith('_txplural')) {
|
|
46
|
+
data[key] = translations[key];
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const baseKey = key.slice(0, -('_txplural'.length));
|
|
50
|
+
const plurals = explodePlurals(translations[key])[1];
|
|
51
|
+
Object.keys(plurals).forEach((plural) => {
|
|
52
|
+
data[`${baseKey}_${plural}`] = plurals[plural];
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const { DefinePlugin } = require('webpack');
|
|
3
|
+
const { version } = require('./package.json');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
|
7
|
+
entry: './src/index.js',
|
|
8
|
+
output: {
|
|
9
|
+
path: path.resolve(__dirname, 'dist'),
|
|
10
|
+
filename: 'browser.i18next.js',
|
|
11
|
+
library: 'TxNativeI18next',
|
|
12
|
+
libraryTarget: 'umd',
|
|
13
|
+
},
|
|
14
|
+
target: 'web',
|
|
15
|
+
devtool: 'source-map',
|
|
16
|
+
plugins: [
|
|
17
|
+
new DefinePlugin({
|
|
18
|
+
__VERSION__: JSON.stringify(version),
|
|
19
|
+
__PLATFORM__: JSON.stringify('browser'),
|
|
20
|
+
}),
|
|
21
|
+
],
|
|
22
|
+
module: {
|
|
23
|
+
rules: [
|
|
24
|
+
{
|
|
25
|
+
test: /\.(js|jsx)$/,
|
|
26
|
+
exclude: /(node_modules)/,
|
|
27
|
+
use: {
|
|
28
|
+
loader: 'babel-loader',
|
|
29
|
+
options: {
|
|
30
|
+
presets: ['@babel/preset-env'],
|
|
31
|
+
plugins: [['@babel/transform-runtime']],
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
};
|
package/webpack.node.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const { DefinePlugin } = require('webpack');
|
|
3
|
+
const { version } = require('./package.json');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
|
7
|
+
entry: './src/index.js',
|
|
8
|
+
output: {
|
|
9
|
+
path: path.resolve(__dirname, 'dist'),
|
|
10
|
+
filename: 'node.i18next.js',
|
|
11
|
+
library: 'transifexI18next',
|
|
12
|
+
libraryTarget: 'umd',
|
|
13
|
+
},
|
|
14
|
+
target: 'node',
|
|
15
|
+
devtool: 'source-map',
|
|
16
|
+
plugins: [
|
|
17
|
+
new DefinePlugin({
|
|
18
|
+
__VERSION__: JSON.stringify(version),
|
|
19
|
+
__PLATFORM__: JSON.stringify('node'),
|
|
20
|
+
}),
|
|
21
|
+
],
|
|
22
|
+
module: {
|
|
23
|
+
rules: [],
|
|
24
|
+
},
|
|
25
|
+
};
|
package/webpack.test.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const glob = require('glob');
|
|
3
|
+
const { DefinePlugin } = require('webpack');
|
|
4
|
+
const { version } = require('./package.json');
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
mode: 'development',
|
|
8
|
+
entry: glob.sync(path.join(__dirname, 'tests/*.test.js')),
|
|
9
|
+
output: {
|
|
10
|
+
path: path.resolve(__dirname, 'dist'),
|
|
11
|
+
filename: 'test.i18next.js',
|
|
12
|
+
},
|
|
13
|
+
target: 'node',
|
|
14
|
+
devtool: 'source-map',
|
|
15
|
+
plugins: [
|
|
16
|
+
new DefinePlugin({
|
|
17
|
+
__VERSION__: JSON.stringify(version),
|
|
18
|
+
__PLATFORM__: JSON.stringify('test'),
|
|
19
|
+
}),
|
|
20
|
+
],
|
|
21
|
+
};
|