Skip to content

Commit

Permalink
Added i18n service to Ghost core
Browse files Browse the repository at this point in the history
refs #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
  • Loading branch information
daniellockyer committed Mar 16, 2023
1 parent 0273ba2 commit 21ea426
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ghost/core/core/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ async function initCore({ghostServer, config, bootLogger, frontend}) {
await settings.syncEmailSettings(config.get('hostSettings:emailVerification:verified'));
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.
debug('Begin: Url Service');
const urlService = require('./server/services/url');
Expand Down
14 changes: 14 additions & 0 deletions ghost/core/core/server/services/i18n.js
Original file line number Diff line number Diff line change
@@ -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'));
});*/
};
1 change: 1 addition & 0 deletions ghost/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"@tryghost/helpers": "1.1.76",
"@tryghost/html-to-plaintext": "0.0.0",
"@tryghost/http-cache-utils": "0.1.7",
"@tryghost/i18n": "0.0.0",
"@tryghost/image-transform": "1.2.4",
"@tryghost/importer-handler-content-files": "0.0.0",
"@tryghost/importer-revue": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion ghost/i18n/lib/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const SUPPORTED_LOCALES = ['en', 'nl'];

/**
* @param {string} [lng]
* @param {'portal'|'test'} ns
* @param {'ghost'|'portal'|'test'} ns
*/
module.exports = (lng = 'en', ns = 'portal') => {
const i18nextInstance = i18next.createInstance();
Expand Down
1 change: 1 addition & 0 deletions ghost/i18n/locales/en/ghost.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions ghost/i18n/locales/nl/ghost.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 2 additions & 1 deletion ghost/i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"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",
"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:test": "NAMESPACE=test i18next './test/**/*.js'"
},
Expand Down

0 comments on commit 21ea426

Please sign in to comment.