You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+106Lines changed: 106 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,3 +3,109 @@
3
3
[](https://www.npmjs.com/package/lit-localize)[](https://github.com/PolymerLabs/lit-localize/actions?query=workflow%3Atests+branch%3Amaster+event%3Apush)
4
4
5
5
WIP
6
+
7
+
## API
8
+
9
+
The `lit-localize` module exports the following functions:
10
+
11
+
### `configureLocalization(configuration)`
12
+
13
+
Set runtime localization configuration.
14
+
15
+
In runtime mode, this function must be called once, before any calls to `msg()`.
16
+
17
+
The `configuration` object must have the following properties:
18
+
19
+
-`sourceLocale: string`: Required locale code in which source templates in this
20
+
project are written, and the initial active locale.
21
+
22
+
-`targetLocales: Iterable<string>`: Required locale codes that are supported by
23
+
this project. Should not include the `sourceLocale` code.
24
+
25
+
-`loadLocale: (locale: string) => Promise<LocaleModule>`: Required function
26
+
that returns a promise of the localized templates for the given locale code.
27
+
For security, this function will only ever be called with a `locale` that is
28
+
contained by `targetLocales`.
29
+
30
+
Example:
31
+
32
+
```typescript
33
+
configureLocalization({
34
+
sourceLocale: 'en',
35
+
targetLocales: ['es-419', 'zh_CN'],
36
+
loadLocale: (locale) =>import(`/${locale}.js`),
37
+
});
38
+
```
39
+
40
+
In transform mode, this function is not required, and calls to it will be
41
+
replaced with `undefined`.
42
+
43
+
### `getLocale(): string`
44
+
45
+
Return the active locale code.
46
+
47
+
In transform mode, calls to this function are transformed into the static locale
48
+
code string for each emitted locale.
49
+
50
+
### `setLocale(locale: string)`
51
+
52
+
Set the active locale code, and begin loading templates for that locale using
53
+
the `loadLocale` function that was passed to `configureLocalization`.
54
+
55
+
In transform mode, calls to this function are replaced with `undefined`.
56
+
57
+
### `localeReady(): Promise`
58
+
59
+
Return a promise that is resolved when the next set of templates are loaded and
60
+
available for rendering. Applications in runtime mode should always `await localeReady()` before rendering.
61
+
62
+
In transform mode, calls to this function are replaced with `undefined`.
0 commit comments