-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(all): Implement stubs for lit-localize support
PiperOrigin-RevId: 474657115
- Loading branch information
1 parent
f75dd05
commit e72ca03
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T extends(string | TemplateResult)>( | ||
template: T, options?: MsgOptions): T { | ||
return template; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`<span>world!</span>` | ||
const result = msg(html`<div tmpl>Hello ${expression}</div>`); | ||
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!'); | ||
}); | ||
}); |