Skip to content

Commit

Permalink
[docs/localization] Update info on messages that map to the same id (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
augustjk authored Jan 31, 2024
1 parent 4529f77 commit bcd88bb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
26 changes: 19 additions & 7 deletions packages/lit-dev-content/site/docs/v2/localization/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ blank.
"tsConfig": "./tsconfig.json",
"output": {
"mode": "runtime",
"outputDir": "./src/generated/locales"
"outputDir": "./src/generated/locales",
"localeCodesModule": "./src/generated/locale-codes.ts"
},
"interchange": {
"format": "xliff",
Expand All @@ -381,7 +382,8 @@ blank.
],
"output": {
"mode": "runtime",
"outputDir": "./src/generated/locales"
"outputDir": "./src/generated/locales",
"localeCodesModule": "./src/generated/locale-codes.js"
},
"interchange": {
"format": "xliff",
Expand Down Expand Up @@ -500,7 +502,7 @@ Descriptions are represented in XLIFF files using `<note>` elements.
```xml
<trans-unit id="s512957aa09384646">
<source>Launch</source>
<note>Button that begins rocket launch sequence.</note>
<note from="lit-localize">Button that begins rocket launch sequence.</note>
</trans-unit>
```

Expand All @@ -518,10 +520,10 @@ have the same content they will be treated as one message:

```js
// file1.js
msg('Hello World')
msg('Hello World');

// file2.js
msg('Hello World')
msg('Hello World');
```

### ID generation
Expand All @@ -537,15 +539,13 @@ The following content **does not** affect ID generation:

- The code inside an expression
- The computed value of an expression
- Descriptions
- File location

For example, all of these messages share the same ID:

```js
msg(html`Hello <b>${name}</b>`);
msg(html`Hello <b>${this.name}</b>`);
msg(html`Hello <b>${this.name}</b>`, {desc: 'A friendly greeting'});
```

But this message has a different ID:
Expand All @@ -554,6 +554,18 @@ But this message has a different ID:
msg(html`Hello <i>${name}</i>`);
```

Note, while providing a [description](#message-descriptions) does not affect ID
generation, multiple messages with the same ID but different description will
produce an error during analysis to avoid ambiguity in the extracted translation
unit. The following is considered **invalid**:

```js
msg(html`Hello <b>${name}</b>`);
msg(html`Hello <b>${name}</b>`, {desc: 'A friendly greeting'});
```

Make sure that all messages with the same ID also have the same description.

### Overriding IDs

Message IDs can be overridden by specifying the `id` option to the `msg`
Expand Down
20 changes: 15 additions & 5 deletions packages/lit-dev-content/site/docs/v3/localization/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ Descriptions are represented in XLIFF files using `<note>` elements.
```xml
<trans-unit id="s512957aa09384646">
<source>Launch</source>
<note>Button that begins rocket launch sequence.</note>
<note from="lit-localize">Button that begins rocket launch sequence.</note>
</trans-unit>
```

Expand All @@ -520,10 +520,10 @@ have the same content they will be treated as one message:

```js
// file1.js
msg('Hello World')
msg('Hello World');

// file2.js
msg('Hello World')
msg('Hello World');
```

### ID generation
Expand All @@ -539,15 +539,13 @@ The following content **does not** affect ID generation:

- The code inside an expression
- The computed value of an expression
- Descriptions
- File location

For example, all of these messages share the same ID:

```js
msg(html`Hello <b>${name}</b>`);
msg(html`Hello <b>${this.name}</b>`);
msg(html`Hello <b>${this.name}</b>`, {desc: 'A friendly greeting'});
```

But this message has a different ID:
Expand All @@ -556,6 +554,18 @@ But this message has a different ID:
msg(html`Hello <i>${name}</i>`);
```

Note, while providing a [description](#message-descriptions) does not affect ID
generation, multiple messages with the same ID but different description will
produce an error during analysis to avoid ambiguity in the extracted translation
unit. The following is considered **invalid**:

```js
msg(html`Hello <b>${name}</b>`);
msg(html`Hello <b>${name}</b>`, {desc: 'A friendly greeting'});
```

Make sure that all messages with the same ID also have the same description.

### Overriding IDs

Message IDs can be overridden by specifying the `id` option to the `msg`
Expand Down

0 comments on commit bcd88bb

Please sign in to comment.