@bemedev/i18n
Version:
Internationalization library for Bemedev projects, providing utilities for managing translations and locale-specific content.
32 lines (28 loc) • 1.13 kB
JavaScript
;
var _class = require('./class.cjs');
var helpers = require('./helpers.cjs');
const _translation = (config, locale) => {
const _class$1 = _class.create(config, locale);
const out = (...args) => _class$1.translate(...args).to(locale);
out.config = config;
return out;
};
/**
* Creates a translation object from a function or object.
* Utility helper to create type-safe translations that match a root config.
*
* @param func - A function that receives defineTranslation or a plain translation object
* @param _ - Optional root config for type inference (not used at runtime)
* @returns The resolved translation object
*/
const translation = (func, locale = 'en-US') => {
const isFunction = typeof func === 'function';
const config = isFunction ? func(helpers.defineTranslation) : func;
return _translation(config, locale);
};
translation.derived = (func, locale = 'en-US') => {
return translation(func, locale);
};
translation.fromMachine = (func, locale = 'en-US') => translation(func, locale);
exports.translation = translation;
//# sourceMappingURL=translation.cjs.map