UNPKG

@ecomplus/utils

Version:

JS utility functions to E-Com Plus (not only) related apps

39 lines 1.35 kB
export default i18n; /** * @method * @memberof ecomUtils * @name i18n * @description Get translated string by lang code from dictionary object. * @param {Object.<string, *>} dictionary - Dictionary object containing string in multiple langs * @param {string} [lang=$ecomConfig.get('lang')] - Snake case language code, eg.: 'en_us', 'pt_br' * @returns {string|Object.<string, *>} * * @example * // With simple dictionary objects * ecomUtils.i18n({ en_us: 'Hello', pt_br: 'Olá' }) * // => 'Hello' * ecomUtils.i18n({ en_us: 'Hello', pt_br: 'Olá' }, 'pt_br') * // => 'Olá' * * @example * // With nested objects * ecomUtils.i18n({ hello: { en_us: 'Hello', pt_br: 'Olá' }}) * // => { hello: 'Hello' } * ecomUtils.i18n({ hello: { en_us: 'Hello', pt_br: 'Olá' }, world: { en_us: 'World' }}, 'pt_br') * // => { hello: 'Olá', world: 'World' } * ecomUtils.i18n({ en_us: { hello: 'Hello', world: 'World' }, pt_br: { hello: 'Olá' }}, 'pt_br') * // => { hello: 'Olá' } * * @example * // You can also set the configured lang first * $ecomConfig.set('lang', 'pt_br') * // Then call `i18n` without expliciting lang * ecomUtils.i18n({ en_us: 'Hello', pt_br: 'Olá' }) * // => Olá */ declare function i18n(dictionary: { [x: string]: any; }, lang?: string): string | { [x: string]: any; }; //# sourceMappingURL=i18n.d.ts.map