Added i18n service to Ghost core

refs https://github.com/TryGhost/Ghost/issues/15502

- this adds the scaffolding for enabling i18n translations within Ghost
  core
- also adds `yarn translate:ghost` as an option to the `i18n` package
- the locale is currently hardcoded to `en` so we don't utilize the
  translations until we're ready
This commit is contained in:
Daniel Lockyer 2023-03-16 14:15:01 +01:00 committed by Daniel Lockyer
parent 0273ba2066
commit 21ea426794
7 changed files with 25 additions and 2 deletions

View File

@ -102,6 +102,11 @@ async function initCore({ghostServer, config, bootLogger, frontend}) {
await settings.syncEmailSettings(config.get('hostSettings:emailVerification:verified')); await settings.syncEmailSettings(config.get('hostSettings:emailVerification:verified'));
debug('End: settings'); debug('End: settings');
debug('Begin: i18n');
const i18n = require('./server/services/i18n');
await i18n.init();
debug('End: i18n');
// The URLService is a core part of Ghost, which depends on models. // The URLService is a core part of Ghost, which depends on models.
debug('Begin: Url Service'); debug('Begin: Url Service');
const urlService = require('./server/services/url'); const urlService = require('./server/services/url');

View File

@ -0,0 +1,14 @@
//const debug = require('@tryghost/debug')('i18n');
const i18n = require('@tryghost/i18n');
module.exports.init = function () {
//const events = require('../lib/common/events');
//const settingsCache = require('../../shared/settings-cache');
module.exports = i18n(/* settingsCache.get('locale') */ 'en', 'ghost');
/*events.on('settings.locale.edited', (model) => {
debug('locale changed, updating i18n to', model.get('value'));
i18nInstance.changeLanguage(model.get('value'));
});*/
};

View File

@ -88,6 +88,7 @@
"@tryghost/helpers": "1.1.76", "@tryghost/helpers": "1.1.76",
"@tryghost/html-to-plaintext": "0.0.0", "@tryghost/html-to-plaintext": "0.0.0",
"@tryghost/http-cache-utils": "0.1.7", "@tryghost/http-cache-utils": "0.1.7",
"@tryghost/i18n": "0.0.0",
"@tryghost/image-transform": "1.2.4", "@tryghost/image-transform": "1.2.4",
"@tryghost/importer-handler-content-files": "0.0.0", "@tryghost/importer-handler-content-files": "0.0.0",
"@tryghost/importer-revue": "0.0.0", "@tryghost/importer-revue": "0.0.0",

View File

@ -4,7 +4,7 @@ const SUPPORTED_LOCALES = ['en', 'nl'];
/** /**
* @param {string} [lng] * @param {string} [lng]
* @param {'portal'|'test'} ns * @param {'ghost'|'portal'|'test'} ns
*/ */
module.exports = (lng = 'en', ns = 'portal') => { module.exports = (lng = 'en', ns = 'portal') => {
const i18nextInstance = i18next.createInstance(); const i18nextInstance = i18next.createInstance();

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1 @@
{}

View File

@ -12,7 +12,8 @@
"lint:code": "eslint *.js lib/ --ext .js --cache", "lint:code": "eslint *.js lib/ --ext .js --cache",
"lint": "yarn lint:code && yarn lint:test", "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": "yarn translate:portal && yarn translate:test", "translate": "yarn translate:ghost && yarn translate:portal && yarn translate:test",
"translate:ghost": "NAMESPACE=ghost i18next '../core/core/{frontend,server,shared}/**/*.{js,jsx}'",
"translate:portal": "NAMESPACE=portal i18next '../portal/src/**/*.{js,jsx}'", "translate:portal": "NAMESPACE=portal i18next '../portal/src/**/*.{js,jsx}'",
"translate:test": "NAMESPACE=test i18next './test/**/*.js'" "translate:test": "NAMESPACE=test i18next './test/**/*.js'"
}, },