actionhero
Version:
actionhero.js is a multi-transport API Server with integrated cluster capabilities and delayed tasks
37 lines (36 loc) • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.i18n = void 0;
const I18n = require("i18n");
const path = require("path");
const config_1 = require("./config");
const dotProp = require("dot-prop");
const options = config_1.config.i18n;
options.directory = path.normalize(config_1.config.general.paths.locale[0]);
I18n.configure(options);
I18n.setLocale(config_1.config.i18n.defaultLocale);
var i18n;
(function (i18n) {
// simplistic determination of locale for connection
function determineConnectionLocale(connection) {
// perhaps you want to look at the `accept-language` headers from a web requests
// perhaps your API can use a certain cookie or URL to determine locale
return config_1.config.i18n.defaultLocale;
}
i18n.determineConnectionLocale = determineConnectionLocale;
function invokeConnectionLocale(connection) {
const cmdParts = config_1.config.i18n.determineConnectionLocale.split(".");
const method = dotProp.get(i18n, cmdParts.join("."));
const locale = method(connection);
I18n.setLocale(connection, locale);
}
i18n.invokeConnectionLocale = invokeConnectionLocale;
/**
* Return a translated string.
*/
function localize(message, object = i18n) {
const messageArray = Array.isArray(message) ? message : [message];
return I18n.__.apply(object, messageArray);
}
i18n.localize = localize;
})(i18n = exports.i18n || (exports.i18n = {}));