Merge pull request #83 from pavelKozlov/ing-bank/fix/LocalizeManager

Add throwing an exception for missing namespace
This commit is contained in:
Joren Broekema 2019-05-31 14:07:44 +02:00 committed by GitHub
commit 832fe392f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 971 additions and 1054 deletions

View file

@ -218,6 +218,11 @@ export class LocalizeManager extends LionSingleton {
}
_getMessageForKey(key, locale) {
if (key.indexOf(':') === -1) {
throw new Error(
`Namespace is missing in the key "${key}". The format for keys is "namespace:name".`,
);
}
const [ns, namesString] = key.split(':');
const namespaces = this.__storage[locale];
const messages = namespaces ? namespaces[ns] : null;

View file

@ -405,5 +405,14 @@ describe('LocalizeManager', () => {
manager.addData('en-GB', 'overridden-ns', { greeting: 'Hello!' });
expect(manager.msg(keys)).to.equal('Hello!');
});
it('throws a custom error when namespace prefix is missing', () => {
const manager = new LocalizeManager();
const msgKey = 'greeting';
manager.addData('en-GB', 'my-ns', { [msgKey]: 'Hello!' });
expect(() => manager.msg(msgKey)).to.throw(
`Namespace is missing in the key "${msgKey}". The format for keys is "namespace:name".`,
);
});
});
});

2011
yarn.lock

File diff suppressed because it is too large Load diff