UNPKG

cloudux-l10n

Version:

Package for providing localization to avid static plugins

51 lines (41 loc) 1.73 kB
/* * Copyright 2016, 2020 by Avid Technology, Inc. */ import { getLocalization } from '../index'; describe('avid-mcux-localization', () => { let localize; let templateString; afterEach(() => { localize = null; templateString = null; }); it('should localize the string', () => { localize = getLocalization({ foo: 'bar' }); expect(localize('foo')).toEqual('bar'); }); it('should localize the string', () => { localize = getLocalization({ foo: 'bar' }); expect(localize('non-existent-key')).toEqual('non-existent-key'); }); it(`should localize the string by using: defined templating values`, () => { localize = getLocalization({ foo: 'bar {0} and {1}' }); expect(localize('foo', 'one', 'two')).toEqual('bar one and two'); }); it('should not substitute parameters if template values are not provided', () => { localize = getLocalization({ foo: 'bar {0} and {1}' }); expect(localize('foo')).toEqual('bar {0} and {1}'); }); it(`should localize the string by using: defined and undefined templating values`, () => { templateString = 'bar {1} and {2}'; localize = getLocalization({ foo: templateString }); expect(localize('foo', 'one', 'two')).toEqual('bar two and undefined'); }); it(`should localize the string by using: templating values in different orders`, () => { templateString = 'bar {0} and {1} and {0} again'; localize = getLocalization({ foo: templateString }); expect(localize('foo', 'one', 'two', 't')).toEqual('bar one and two and one again'); }); });