2018-01-09 16:50:57 +03:00
|
|
|
// # 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 ")}}
|
|
|
|
|
2020-04-08 18:56:37 +03:00
|
|
|
const {themeI18n} = require('../services/proxy');
|
2018-01-09 16:50:57 +03:00
|
|
|
|
|
|
|
module.exports = function t(text, options) {
|
2020-04-29 18:44:27 +03:00
|
|
|
const bindings = {};
|
|
|
|
let prop;
|
2018-01-09 16:50:57 +03:00
|
|
|
for (prop in options.hash) {
|
2019-08-08 11:47:13 +03:00
|
|
|
if (Object.prototype.hasOwnProperty.call(options.hash, prop)) {
|
2018-01-09 16:50:57 +03:00
|
|
|
bindings[prop] = options.hash[prop];
|
|
|
|
}
|
|
|
|
}
|
2020-03-19 17:07:20 +03:00
|
|
|
|
|
|
|
return themeI18n.t(text, bindings);
|
2018-01-09 16:50:57 +03:00
|
|
|
};
|