mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03:00
Moved i18n basePath concept from themes to core
- we need the basePath concept for the main i18n class so we can pull it out into a module - we already had this in the themeI18n class, so I just had to move it up - also I added a default of __dirname, so we don't have to declare this constantly in the tests
This commit is contained in:
parent
ccbb44bc67
commit
15fad7837f
@ -11,21 +11,6 @@ class ThemeI18n extends i18n.I18n {
|
||||
super(options);
|
||||
// We don't care what gets passed in, themes use fulltext mode
|
||||
this._stringMode = 'fulltext';
|
||||
this._basePath = options.basePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* BasePath getter & setter used for testing
|
||||
*/
|
||||
set basePath(basePath) {
|
||||
this._basePath = basePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Need to call init after this
|
||||
*/
|
||||
get basePath() {
|
||||
return this._basePath;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,11 +13,13 @@ const get = require('lodash/get');
|
||||
class I18n {
|
||||
/**
|
||||
* @param {objec} [options]
|
||||
* @param {string} basePath - the base path to the translations directory
|
||||
* @param {string} [locale] - a locale string
|
||||
* @param {{dot|fulltext}} [stringMode] - which mode our translation keys use
|
||||
* @param {{object}} [logging] - logging method
|
||||
*/
|
||||
constructor(options = {}) {
|
||||
this._basePath = options.basePath || __dirname;
|
||||
this._locale = options.locale || this.defaultLocale();
|
||||
this._stringMode = options.stringMode || 'dot';
|
||||
this._logging = options.logging || console;
|
||||
@ -25,6 +27,20 @@ class I18n {
|
||||
this._strings = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* BasePath getter & setter used for testing
|
||||
*/
|
||||
set basePath(basePath) {
|
||||
this._basePath = basePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Need to call init after this
|
||||
*/
|
||||
get basePath() {
|
||||
return this._basePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* English is our default locale
|
||||
*/
|
||||
@ -185,7 +201,7 @@ class I18n {
|
||||
}
|
||||
|
||||
_translationFileDirs() {
|
||||
return [__dirname, 'translations'];
|
||||
return [this.basePath];
|
||||
}
|
||||
|
||||
// If we are passed a locale, use that, else use this.locale
|
||||
|
@ -1,6 +1,6 @@
|
||||
const path = require('path');
|
||||
const logging = require('../logging');
|
||||
|
||||
const I18n = require('./i18n');
|
||||
|
||||
module.exports = new I18n({logging});
|
||||
module.exports = new I18n({logging, basePath: path.join(__dirname, 'translations')});
|
||||
module.exports.I18n = I18n;
|
||||
|
Loading…
Reference in New Issue
Block a user