mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
5e2c62e328
- 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.
25 lines
1,011 B
JavaScript
25 lines
1,011 B
JavaScript
// # t helper
|
|
// i18n: Translatable handlebars expressions for templates of the front-end and themes.
|
|
// Front-end: .hbs templates in core/server, overridden by copies in themes. Themes: in content/themes.
|
|
//
|
|
// Usage examples, for example in .hbs theme templates:
|
|
// {{t "Get the latest posts delivered right to your inbox"}}
|
|
// {{{t "Proudly published with {ghostlink}" ghostlink="<a href=\"https://ghost.org\">Ghost</a>"}}}
|
|
//
|
|
// To preserve HTML, use {{{t}}}. This helper doesn't use a SafeString object which would prevent escaping,
|
|
// because often other helpers need that (t) returns a string to be able to work as subexpression; e.g.:
|
|
// {{tags prefix=(t " on ")}}
|
|
|
|
const {themeI18n} = require('./proxy');
|
|
|
|
module.exports = function t(text, options) {
|
|
var bindings = {},
|
|
prop;
|
|
for (prop in options.hash) {
|
|
if (Object.prototype.hasOwnProperty.call(options.hash, prop)) {
|
|
bindings[prop] = options.hash[prop];
|
|
}
|
|
}
|
|
|
|
return themeI18n.t(text, bindings);
|
|
};
|