mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03:00
Refactored i18n into a class + index
- preparation for using DI instead of requires, so we can move this out of Ghost - have done this for both the main i18n and theme i18n file - refactored the constructor
This commit is contained in:
parent
7360be5625
commit
ba53de1add
@ -1,15 +1,15 @@
|
||||
const errors = require('@tryghost/errors');
|
||||
const i18n = require('../../../shared/i18n');
|
||||
const logging = require('../../../shared/logging');
|
||||
const settingsCache = require('../../../server/services/settings/cache');
|
||||
const config = require('../../../shared/config');
|
||||
const i18n = require('../../../../shared/i18n');
|
||||
const logging = require('../../../../shared/logging');
|
||||
const settingsCache = require('../../../../server/services/settings/cache');
|
||||
const config = require('../../../../shared/config');
|
||||
const jp = require('jsonpath');
|
||||
|
||||
const isNil = require('lodash/isNil');
|
||||
|
||||
class ThemeI18n extends i18n.I18n {
|
||||
constructor(locale) {
|
||||
super(locale);
|
||||
constructor(options = {}) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,6 +93,4 @@ class ThemeI18n extends i18n.I18n {
|
||||
}
|
||||
}
|
||||
|
||||
let themeI18n = new ThemeI18n();
|
||||
|
||||
module.exports = themeI18n;
|
||||
module.exports = ThemeI18n;
|
5
core/frontend/services/theme-engine/i18n/index.js
Normal file
5
core/frontend/services/theme-engine/i18n/index.js
Normal file
@ -0,0 +1,5 @@
|
||||
const ThemeI18n = require('./i18n');
|
||||
const themeI18n = new ThemeI18n();
|
||||
|
||||
module.exports = themeI18n;
|
||||
module.exports.ThemeI18n = ThemeI18n;
|
@ -9,11 +9,11 @@ const isNil = require('lodash/isNil');
|
||||
const merge = require('lodash/merge');
|
||||
const get = require('lodash/get');
|
||||
const errors = require('@tryghost/errors');
|
||||
const logging = require('./logging');
|
||||
const logging = require('../logging');
|
||||
|
||||
class I18n {
|
||||
constructor(locale) {
|
||||
this._locale = locale || this.defaultLocale();
|
||||
constructor(options = {}) {
|
||||
this._locale = options.locale || this.defaultLocale();
|
||||
this._strings = null;
|
||||
}
|
||||
|
||||
@ -212,5 +212,4 @@ class I18n {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new I18n();
|
||||
module.exports.I18n = I18n;
|
||||
module.exports = I18n;
|
4
core/shared/i18n/index.js
Normal file
4
core/shared/i18n/index.js
Normal file
@ -0,0 +1,4 @@
|
||||
const I18n = require('./i18n');
|
||||
|
||||
module.exports = new I18n();
|
||||
module.exports.I18n = I18n;
|
10
test/unit/services/theme-engine/i18n_spec.js
Normal file
10
test/unit/services/theme-engine/i18n_spec.js
Normal file
@ -0,0 +1,10 @@
|
||||
const should = require('should');
|
||||
|
||||
const ThemeI18n = require('../../../../core/frontend/services/theme-engine/i18n').ThemeI18n;
|
||||
|
||||
describe('ThemeI18n Class Behaviour', function () {
|
||||
it('defaults to en', function () {
|
||||
const i18n = new ThemeI18n();
|
||||
i18n.locale().should.eql('en');
|
||||
});
|
||||
});
|
10
test/unit/shared/i18n_spec.js
Normal file
10
test/unit/shared/i18n_spec.js
Normal file
@ -0,0 +1,10 @@
|
||||
const should = require('should');
|
||||
|
||||
const I18n = require('../../../core/shared/i18n').I18n;
|
||||
|
||||
describe('I18n Class Behaviour', function () {
|
||||
it('defaults to en', function () {
|
||||
const i18n = new I18n();
|
||||
i18n.locale().should.eql('en');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user