UNPKG

@bemedev/i18n

Version:

Internationalization library for Bemedev projects, providing utilities for managing translations and locale-specific content.

30 lines (27 loc) 1.09 kB
import { create } from './class.js'; import { defineTranslation } from './helpers.js'; const _translation = (config, locale) => { const _class = create(config, locale); const out = (...args) => _class.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(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); export { translation }; //# sourceMappingURL=translation.js.map