Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lion/localize

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lion/localize - npm Package Compare versions

Comparing version 0.3.6 to 0.4.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [0.4.0](https://github.com/ing-bank/lion/compare/@lion/localize@0.3.6...@lion/localize@0.4.0) (2019-06-06)
### Features
* **localize:** allow custom locale when loading namespaces ([2e76ca0](https://github.com/ing-bank/lion/commit/2e76ca0))
## [0.3.6](https://github.com/ing-bank/lion/compare/@lion/localize@0.3.5...@lion/localize@0.3.6) (2019-05-31)

@@ -8,0 +19,0 @@

4

package.json
{
"name": "@lion/localize",
"version": "0.3.6",
"version": "0.4.0",
"description": "The localization system helps to manage localization data split into locales and automate its loading",

@@ -44,3 +44,3 @@ "author": "ing-bank",

},
"gitHead": "591ef9f4fa42c4233b66ea85e5fcea8f6b12db63"
"gitHead": "1f6b2833d72fcbee379761e9e0429b0b6843fcd2"
}

@@ -62,7 +62,7 @@ import MessageFormat from '@bundled-es-modules/message-format/MessageFormat.js';

loadNamespaces(namespaces) {
return Promise.all(namespaces.map(namespace => this.loadNamespace(namespace)));
loadNamespaces(namespaces, { locale } = {}) {
return Promise.all(namespaces.map(namespace => this.loadNamespace(namespace, { locale })));
}
loadNamespace(namespaceObj) {
loadNamespace(namespaceObj, { locale = this.locale } = { locale: this.locale }) {
const isDynamicImport = typeof namespaceObj === 'object';

@@ -72,7 +72,7 @@

if (this._isNamespaceInCache(this.locale, namespace)) {
if (this._isNamespaceInCache(locale, namespace)) {
return Promise.resolve();
}
const existingLoaderPromise = this._getCachedNamespaceLoaderPromise(this.locale, namespace);
const existingLoaderPromise = this._getCachedNamespaceLoaderPromise(locale, namespace);
if (existingLoaderPromise) {

@@ -82,3 +82,3 @@ return existingLoaderPromise;

return this._loadNamespaceData(this.locale, namespaceObj, isDynamicImport, namespace);
return this._loadNamespaceData(locale, namespaceObj, isDynamicImport, namespace);
}

@@ -85,0 +85,0 @@

@@ -119,2 +119,22 @@ import { expect, oneEvent } from '@open-wc/testing';

it('can load a namespace for a different locale', async () => {
setupFakeImport('./my-component/nl-NL.js', { default: { greeting: 'Hello!' } });
const manager = new LocalizeManager();
manager.locale = 'en-US';
await manager.loadNamespace(
{
'my-component': locale => fakeImport(`./my-component/${locale}.js`),
},
{ locale: 'nl-NL' },
);
expect(manager.__storage).to.deep.equal({
'nl-NL': {
'my-component': { greeting: 'Hello!' },
},
});
});
it('loads multiple namespaces via loadNamespaces()', async () => {

@@ -139,2 +159,25 @@ setupFakeImport('./my-defaults/en-GB.js', { default: { submit: 'Submit' } });

it('can load multiple namespaces for a different locale', async () => {
setupFakeImport('./my-defaults/nl-NL.js', { default: { submit: 'Submit' } });
setupFakeImport('./my-send-button/nl-NL.js', { default: { submit: 'Send' } });
const manager = new LocalizeManager();
manager.locale = 'en-US';
await manager.loadNamespaces(
[
{ 'my-defaults': locale => fakeImport(`./my-defaults/${locale}.js`) },
{ 'my-send-button': locale => fakeImport(`./my-send-button/${locale}.js`) },
],
{ locale: 'nl-NL' },
);
expect(manager.__storage).to.deep.equal({
'nl-NL': {
'my-defaults': { submit: 'Submit' },
'my-send-button': { submit: 'Send' },
},
});
});
it('fallbacks to language file if locale file is not found', async () => {

@@ -141,0 +184,0 @@ setupFakeImport('./my-component/en.js', { default: { greeting: 'Hello!' } });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc