@computerrock/formation-i18n
Advanced tools
Comparing version 0.3.3 to 0.4.0
{ | ||
"name": "@computerrock/formation-i18n", | ||
"version": "0.3.3", | ||
"version": "0.4.0", | ||
"description": "Formation framework - i18n layer", | ||
@@ -34,3 +34,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "e1228ddfecfb4b9cb06a68d62bea0dcff5e84781" | ||
"gitHead": "86434675736b86b3ffb6a524c8888c2ee04fd809" | ||
} |
@@ -20,2 +20,3 @@ import handleResponse from './handleResponse'; | ||
let activeLocaleSet = {}; | ||
let availableLocaleSets = {}; | ||
let availableLocales = []; | ||
@@ -78,2 +79,3 @@ | ||
activeLocaleSet = allLocaleSets[activeLocale]; | ||
availableLocaleSets = allLocaleSets; | ||
availableLocales = Object.keys(allLocaleSets).map(key => ({ | ||
@@ -109,6 +111,9 @@ locale: key, | ||
const translate = (key = 'key', params = {}) => { | ||
if (typeof activeLocaleSet[key] === 'undefined') return key; | ||
const translate = (key = 'key', params = {}, locale) => { | ||
const localeSet = typeof locale !== 'string' ? activeLocaleSet | ||
: (typeof availableLocaleSets[locale] !== 'undefined' ? availableLocaleSets[locale] : {}); | ||
let translation = activeLocaleSet[key]; | ||
if (typeof localeSet[key] === 'undefined') return key; | ||
let translation = localeSet[key]; | ||
Object.keys(params).forEach(key => { | ||
@@ -121,4 +126,4 @@ translation = translation.replace(new RegExp(`{${key}}`, 'g'), params[key]); | ||
const createTranslateShorthand = (keyRoot = 'key_root') => { | ||
return (shorthandKey = 'shorthand_key', params) => translate(`${keyRoot}.${shorthandKey}`, params); | ||
const createTranslateShorthand = (keyRoot = 'key_root') => (shorthandKey = 'shorthand_key', params, locale) => { | ||
return translate(`${keyRoot}.${shorthandKey}`, params, locale); | ||
}; | ||
@@ -125,0 +130,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12774
291
2