0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00
ghost/core/test/unit/helpers/t_spec.js
Hannah Wolfe 5e2c62e328
Moved theme i18n into theme service + refactor (#11674)
- The existing common.i18n library contained code for core and theme translations
- There is some shared logic and some theme-specific logic, and the theme-specific logic has dependencies we don't want in lib/common
- This refactor introduces an I18n base class that does all the main shared logic, with no dependencies on other parts of the codebase
- ThemeI18n then extends this logic, and replaces the functions it needs to handle differently and adds it's dependencies on config and settingsCache
- The class has several methods broken down into smaller pieces to make it easier to extend only the necessary parts
- The class also encapsulates all of its logic, without external functions or variables
- The function loadThemeTranslations becomes the 'init()' function overridden in themeI18n.
2020-03-19 14:07:20 +00:00

63 lines
1.9 KiB
JavaScript

const should = require('should');
const path = require('path');
const settingsCache = require('../../../server/services/settings/cache');
const helpers = require('../../../frontend/helpers');
const themeI18n = require('../../../frontend/services/themes/i18n');
const configUtils = require('../../utils/configUtils');
describe('{{t}} helper', function () {
beforeEach(function () {
settingsCache.set('active_theme', {value: 'casper'});
configUtils.set('paths:contentPath', path.join(__dirname, '../../utils/fixtures/'));
});
afterEach(function () {
configUtils.restore();
settingsCache.shutdown();
});
it('theme translation is DE', function () {
settingsCache.set('default_locale', {value: 'de'});
themeI18n.init();
let rendered = helpers.t.call({}, 'Top left Button', {
hash: {}
});
rendered.should.eql('Oben Links.');
});
it('theme translation is EN', function () {
settingsCache.set('default_locale', {value: 'en'});
themeI18n.init();
let rendered = helpers.t.call({}, 'Top left Button', {
hash: {}
});
rendered.should.eql('Left Button on Top');
});
it('[fallback] no theme translation file found for FR', function () {
settingsCache.set('default_locale', {value: 'fr'});
themeI18n.init();
let rendered = helpers.t.call({}, 'Top left Button', {
hash: {}
});
rendered.should.eql('Left Button on Top');
});
it('[fallback] no theme files at all, use key as translation', function () {
settingsCache.set('active_theme', {value: 'casper-1.4'});
settingsCache.set('default_locale', {value: 'de'});
themeI18n.init();
let rendered = helpers.t.call({}, 'Top left Button', {
hash: {}
});
rendered.should.eql('Top left Button');
});
});