diff --git a/localization/localize.ts b/localization/localize.ts new file mode 100644 index 0000000000..9d3dffa0d3 --- /dev/null +++ b/localization/localize.ts @@ -0,0 +1,29 @@ +/** + * @license + * Copyright 2022 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import {TemplateResult} from 'lit'; + +/** Options object to the `msg()` function */ +export interface MsgOptions { + id?: string; + desc?: string; +} + +/** stand-in for lit-localize str function */ +export function str( + strings: TemplateStringsArray, ...values: unknown[]): string { + let out = strings[0]; + for (let i = 1; i < strings.length; i++) { + out += String(values[i - 1]) + strings[i]; + } + return out; +} + +/** stand-in for lit-localize msg function */ +export function msg( + template: T, options?: MsgOptions): T { + return template; +} \ No newline at end of file diff --git a/localization/localize_test.ts b/localization/localize_test.ts new file mode 100644 index 0000000000..2af0e31a7a --- /dev/null +++ b/localization/localize_test.ts @@ -0,0 +1,29 @@ +/** + * @license + * Copyright 2022 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import 'jasmine'; + +import {html} from 'lit'; + +import {msg, str} from './localize.js'; + + +describe('localize test', () => { + it('passes through TemplateResults', () => { + const expression = html`world!` + const result = msg(html`
Hello ${expression}
`); + expect(msg(result)).toEqual(result); + }); + + it('passes through strings', () => { + expect(msg('Hello!')).toEqual('Hello!'); + }); + + it('converts str templates to strings', () => { + const expression = 'world'; + expect(msg(str`Hello ${expression}!`)).toEqual('Hello world!'); + }); +});