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: frontend/docs/docs/develop/localization.md
+76-1Lines changed: 76 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,7 @@ Adding support for a new language involves a small code change. If you'd like to
15
15
To add a new language directly through code change:
16
16
17
17
1. Look up the [BCP 47 language tag](https://www.w3.org/International/articles/language-tags/index.en#registry) and add it to the `targetLocales` field in `lit-localize.json`.
18
+
18
19
```js
19
20
{
20
21
// ...
@@ -27,9 +28,11 @@ To add a new language directly through code change:
27
28
```
28
29
29
30
2. Generate a new XLIFF file by running:
31
+
30
32
```sh
31
33
yarn localize:extract
32
34
```
35
+
33
36
This will add an `.xlf` file named after the new language tag to the `/xliff` directory.
34
37
35
38
3. Open a pull request with the changes.
@@ -54,4 +57,76 @@ render() {
54
57
}
55
58
```
56
59
57
-
See [Lit's message types documentation](https://lit.dev/docs/localization/overview/#message-types) page for details.
60
+
### Handling expressions in strings
61
+
62
+
Expressions can be included in strings:
63
+
64
+
```js
65
+
import { msg, str } from"@lit/localize";
66
+
67
+
msg(str`Welcome, ${name}.`)
68
+
```
69
+
70
+
Translators will see the string expression as-written in code. To aid translations, avoid calculations in expressions and choose a descriptive variable name.
71
+
72
+
```js
73
+
// Instead of this:
74
+
//
75
+
// msg(str`This file exceeds the maximum of ${5 * 1000 * 1000} bytes.`).
76
+
77
+
// Try this:
78
+
constbytes=5*1000*1000;
79
+
80
+
msg(str`This file exceeds the maximum of ${bytes} bytes.`).
81
+
```
82
+
83
+
Dates and numbers should be localized and pluralized in source code before being assigned to the message string.
msg(str`You have ${number_of_URLs} pending as of ${date}.`);
96
+
```
97
+
98
+
!!! Tip "Tip: Include a message description for translators."
99
+
You can add additional context for translators using the `desc` option when the variable name may be ambiguous by itself.
100
+
101
+
Building on the previous example:
102
+
103
+
```js
104
+
msg(str`You have ${number_of_URLs} pending as of ${date}.`, {
105
+
desc: "`number_of_URLs` example: '1,000 URLs'"
106
+
});
107
+
```
108
+
109
+
### Handling HTML in strings
110
+
111
+
Lit supports HTML in translation strings. However, try to avoid including markup in strings by using multiple `msg()`s, as HTML makes it more difficult for translators to update strings in the Weblate interface, as well as more performance overhead.
112
+
113
+
```js
114
+
// Instead of this:
115
+
//
116
+
// msg(html`Would you like to continue? <button>Continue</button>`)
117
+
118
+
// Do this:
119
+
html`
120
+
${msg("Would you like to continue?")} <button>${msg("Continue")}</button>
121
+
`
122
+
```
123
+
124
+
When markup is unavoidable, prefer assigning the template to a variable.
0 commit comments