Skip to content

Commit 2cf1611

Browse files
committed
Added yarn translate:portal command
refs #15502 - the amazing `i18next-parser` dependency will extract our translated strings from Portal and dump them into locale files, so we never have to add them manually
1 parent 3634815 commit 2cf1611

File tree

4 files changed

+526
-26
lines changed

4 files changed

+526
-26
lines changed

ghost/i18n/i18next-parser.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const {SUPPORTED_LOCALES} = require('./');
2+
3+
module.exports = {
4+
locales: SUPPORTED_LOCALES,
5+
6+
keySeparator: false,
7+
namespaceSeparator: false,
8+
9+
sort: true,
10+
11+
output: 'locales/$LOCALE.json'
12+
};

ghost/i18n/lib/i18n.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
const i18next = require('i18next');
22

3+
const RESOURCES = {
4+
en: {
5+
translation: require('../locales/en.json')
6+
},
7+
nl: {
8+
translation: require('../locales/nl.json')
9+
}
10+
};
11+
12+
const SUPPORTED_LOCALES = Object.keys(RESOURCES);
13+
314
module.exports = (lng = 'en') => {
415
const i18nextInstance = i18next.createInstance();
516
i18nextInstance.init({
@@ -13,15 +24,10 @@ module.exports = (lng = 'en') => {
1324
// do not load a fallback
1425
fallbackLng: false,
1526

16-
resources: {
17-
en: {
18-
translation: require('../locales/en.json')
19-
},
20-
nl: {
21-
translation: require('../locales/nl.json')
22-
}
23-
}
27+
resources: RESOURCES
2428
});
2529

2630
return i18nextInstance;
2731
};
32+
33+
module.exports.SUPPORTED_LOCALES = SUPPORTED_LOCALES;

ghost/i18n/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
"main": "index.js",
88
"scripts": {
99
"dev": "echo \"Implement me!\"",
10-
"test:unit": "NODE_ENV=testing c8 --all --check-coverage --100 --reporter text --reporter cobertura mocha './test/**/*.test.js'",
10+
"test:unit": "NODE_ENV=testing c8 --include index.js --include lib --check-coverage --100 --reporter text --reporter cobertura mocha './test/**/*.test.js'",
1111
"test": "yarn test:unit",
1212
"lint:code": "eslint *.js lib/ --ext .js --cache",
1313
"lint": "yarn lint:code && yarn lint:test",
14-
"lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache"
14+
"lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache",
15+
"translate:portal": "i18next '../portal/src/**/*.{js,jsx}'"
1516
},
1617
"files": [
1718
"index.js",
@@ -20,6 +21,7 @@
2021
],
2122
"devDependencies": {
2223
"c8": "7.12.0",
24+
"i18next-parser": "7.6.0",
2325
"mocha": "10.2.0"
2426
},
2527
"dependencies": {

0 commit comments

Comments
 (0)