| 1 |
/** |
| 2 |
* @license |
| 3 |
* Copyright 2020 Google LLC |
| 4 |
* SPDX-License-Identifier: BSD-3-Clause |
| 5 |
*/ |
| 6 |
import {LitElement, html} from 'lit'; |
| 7 |
const {getLocale} = {getLocale: () => 'zh_CN'}; |
| 8 |
console.log(`Locale is ${getLocale()}`); |
| 9 |
window.addEventListener('lit-localize-status', (event) => { |
| 10 |
console.log(event.detail.status); |
| 11 |
}); |
| 12 |
const user = 'Friend'; |
| 13 |
const url = 'https://www.example.com/'; |
| 14 |
// Plain string |
| 15 |
`\u4F60\u597D\uFF0C\u4E16\u754C!`; |
| 16 |
// Plain string with expression |
| 17 |
`Hello ${user}!`; |
| 18 |
// Lit template |
| 19 |
html`你好 <b>世界</b>!`; |
| 20 |
// Lit template with one XLIFF placeholder (combined start tag + expression + |
| 21 |
// end tag). |
| 22 |
html`Hello <b>${user}</b>!`; |
| 23 |
// Lit template with two XLIFF placeholders (combined start tag + expression, |
| 24 |
// separate end tag). |
| 25 |
html`Click <a href=${url}>here</a>!`; |
| 26 |
// Lit template with string expression |
| 27 |
// |
| 28 |
// TODO(aomarks) The "SALT" text is here because we have a check to make sure |
| 29 |
// that two messages can't have the same ID unless they have identical template |
| 30 |
// contents. After https://github.com/lit/lit/issues/1621 is |
| 31 |
// implemented, add a "meaning" parameter instead. |
| 32 |
html`[SALT] Click <a href="https://www.example.com/">here</a>!`; |
| 33 |
// Lit template with nested msg expression |
| 34 |
html`[SALT] Hello <b>World</b>!`; |
| 35 |
// Lit template with comment |
| 36 |
html`Hello <b><!-- comment -->World</b>!`; |
| 37 |
// Custom ID |
| 38 |
('Hello World'); |
| 39 |
// updateWhenLocaleChanges -> undefined |
| 40 |
export class MyElement1 extends LitElement { |
| 41 |
constructor() { |
| 42 |
super(); |
| 43 |
undefined; |
| 44 |
} |
| 45 |
render() { |
| 46 |
return html`<p>你好 <b>世界</b>! (${getLocale()})</p>`; |
| 47 |
} |
| 48 |
} |
| 49 |
// @localized -> removed |
| 50 |
export class MyElement2 extends LitElement { |
| 51 |
render() { |
| 52 |
return html`<p>你好 <b>世界</b>! (${getLocale()})</p>`; |
| 53 |
} |
| 54 |
} |
| 55 |
// Escaped markup characters should remain escaped |
| 56 |
html`<Hello<b><World & Friends></b>!>`; |
| 57 |
// Expressions as attribute values should stay as expressions |
| 58 |
html`Hello <b foo=${'World'}>World</b>`; |
| 59 |
html`Hello <b foo=${'World'}>World</b>`; |
| 60 |
html`<b foo=${'Hello'}>Hello</b><b bar=${'World'}>World</b>`; |
| 61 |
html`Hello <b .foo=${'World'}>World</b>`; |
| 62 |
html`Hello <b .foo=${'World'}>World</b>`; |
| 63 |
// Placeholder in translation has different expression |
| 64 |
`Different ${user}`; |
| 65 |
html`Different <b>${user}</b>`; |