Skip to content

Commit

Permalink
Added yarn translate:portal command
Browse files Browse the repository at this point in the history
refs TryGhost#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
  • Loading branch information
daniellockyer authored and 9larsons committed Jan 19, 2023
1 parent 734141a commit 2d71c0c
Show file tree
Hide file tree
Showing 4 changed files with 526 additions and 26 deletions.
12 changes: 12 additions & 0 deletions ghost/i18n/i18next-parser.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const {SUPPORTED_LOCALES} = require('./');

module.exports = {
locales: SUPPORTED_LOCALES,

keySeparator: false,
namespaceSeparator: false,

sort: true,

output: 'locales/$LOCALE.json'
};
22 changes: 14 additions & 8 deletions ghost/i18n/lib/i18n.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
const i18next = require('i18next');

const RESOURCES = {
en: {
translation: require('../locales/en.json')
},
nl: {
translation: require('../locales/nl.json')
}
};

const SUPPORTED_LOCALES = Object.keys(RESOURCES);

module.exports = (lng = 'en') => {
const i18nextInstance = i18next.createInstance();
i18nextInstance.init({
Expand All @@ -13,15 +24,10 @@ module.exports = (lng = 'en') => {
// do not load a fallback
fallbackLng: false,

resources: {
en: {
translation: require('../locales/en.json')
},
nl: {
translation: require('../locales/nl.json')
}
}
resources: RESOURCES
});

return i18nextInstance;
};

module.exports.SUPPORTED_LOCALES = SUPPORTED_LOCALES;
6 changes: 4 additions & 2 deletions ghost/i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
"main": "index.js",
"scripts": {
"dev": "echo \"Implement me!\"",
"test:unit": "NODE_ENV=testing c8 --all --check-coverage --100 --reporter text --reporter cobertura mocha './test/**/*.test.js'",
"test:unit": "NODE_ENV=testing c8 --include index.js --include lib --check-coverage --100 --reporter text --reporter cobertura mocha './test/**/*.test.js'",
"test": "yarn test:unit",
"lint:code": "eslint *.js lib/ --ext .js --cache",
"lint": "yarn lint:code && yarn lint:test",
"lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache"
"lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache",
"translate:portal": "i18next '../portal/src/**/*.{js,jsx}'"
},
"files": [
"index.js",
Expand All @@ -20,6 +21,7 @@
],
"devDependencies": {
"c8": "7.12.0",
"i18next-parser": "7.6.0",
"mocha": "10.2.0"
},
"dependencies": {
Expand Down
Loading

0 comments on commit 2d71c0c

Please sign in to comment.