New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

factorial-i18n

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

factorial-i18n - npm Package Compare versions

Comparing version

to
0.0.4

13

__tests__/index.spec.js

@@ -53,3 +53,4 @@ import I18n from '../src'

beforeEach(() => {
i18n = new I18n(mockedTranslations, ['en', 'es'])
i18n = new I18n()
i18n.setTranslations(mockedTranslations)
process.env.NODE_ENV = 'development'

@@ -71,8 +72,2 @@ })

describe('with default locale', () => {
it('uses english', () => {
expect(i18n.t('common.loading')).toBe('loading')
})
})
describe('with spanish locale', () => {

@@ -94,5 +89,5 @@ beforeEach(() => {

it('interpolates and escapes', () => {
it('interpolates and do not escapes', () => {
expect(i18n.t('hello', { name: '<b>coca-cola</b>' })).toBe(
'hola &lt;b&gt;coca-cola&lt;/b&gt;'
'hola <b>coca-cola</b>'
)

@@ -99,0 +94,0 @@ })

@@ -29,14 +29,15 @@ 'use strict';

var DEFAULT_LOCALE = 'en';
var I18n = function () {
function I18n(translations, supportedLocales) {
function I18n() {
_classCallCheck(this, I18n);
this.translations = translations;
this.supportedLocales = supportedLocales;
this.locale = 'en';
this.translations = {};
}
_createClass(I18n, [{
key: 'setTranslations',
value: function setTranslations(translations) {
this.translations = translations;
}
}, {
key: 'setLocale',

@@ -69,16 +70,3 @@ value: function setLocale(locale) {

value: function getKey(path) {
var _this = this;
var result = _lodash2.default.at(this.translations[this.locale], path)[0] || _lodash2.default.at(this.translations[DEFAULT_LOCALE], path)[0];
if (process.env.NODE_ENV === 'development') {
// We check that the translation exists in all current supportedLocales!
this.supportedLocales.forEach(function (locale) {
if (_lodash2.default.at(_this.translations[locale], path)[0]) return;
console.warn('Key not found "' + path + '" with the locale "' + locale + '"');
});
}
return result;
return _lodash2.default.at(this.translations[this.locale], path)[0];
}

@@ -109,3 +97,3 @@

}
return _lodash2.default.escape(String(opts[subst]));
return String(opts[subst]);
});

@@ -112,0 +100,0 @@ }

{
"name": "factorial-i18n",
"version": "0.0.3",
"version": "0.0.4",
"description": "Factorial i18n library",

@@ -5,0 +5,0 @@ "repository": {

@@ -30,4 +30,5 @@ # Factorial i18n

const i18n = new I18n(translation, ['es', 'en'])
const i18n = new I18n()
i18n.setTranslations(translations)
i18n.setLocale('es')

@@ -34,0 +35,0 @@ i18n.t('common.hello') // => Hola

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet