UNPKG

@inkline/inkline

Version:

Inkline is the Vue.js UI/UX Library built for creating your next design system

16 lines 601 B
import { getValueByPath, isFunction } from '../helpers/index.mjs'; import { i18n } from './/index.mjs'; /** * Translate a string given its path and translation params * * @param path * @param params */ export function translate(path, params = {}) { const valueByPath = getValueByPath(i18n.messages[i18n.locale], path); const string = isFunction(valueByPath) ? valueByPath(params) : valueByPath || path; return Object.keys(params).reduce((acc, key) => { return acc.replace(new RegExp(`{${key}}`, 'g'), `${params[key]}`); }, string); } //# sourceMappingURL=translate.mjs.map