Skip to content

Commit bcd88bb

Browse files
authored
[docs/localization] Update info on messages that map to the same id (#1301)
1 parent 4529f77 commit bcd88bb

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

packages/lit-dev-content/site/docs/v2/localization/overview.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ blank.
362362
"tsConfig": "./tsconfig.json",
363363
"output": {
364364
"mode": "runtime",
365-
"outputDir": "./src/generated/locales"
365+
"outputDir": "./src/generated/locales",
366+
"localeCodesModule": "./src/generated/locale-codes.ts"
366367
},
367368
"interchange": {
368369
"format": "xliff",
@@ -381,7 +382,8 @@ blank.
381382
],
382383
"output": {
383384
"mode": "runtime",
384-
"outputDir": "./src/generated/locales"
385+
"outputDir": "./src/generated/locales",
386+
"localeCodesModule": "./src/generated/locale-codes.js"
385387
},
386388
"interchange": {
387389
"format": "xliff",
@@ -500,7 +502,7 @@ Descriptions are represented in XLIFF files using `<note>` elements.
500502
```xml
501503
<trans-unit id="s512957aa09384646">
502504
<source>Launch</source>
503-
<note>Button that begins rocket launch sequence.</note>
505+
<note from="lit-localize">Button that begins rocket launch sequence.</note>
504506
</trans-unit>
505507
```
506508

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

519521
```js
520522
// file1.js
521-
msg('Hello World')
523+
msg('Hello World');
522524

523525
// file2.js
524-
msg('Hello World')
526+
msg('Hello World');
525527
```
526528

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

538540
- The code inside an expression
539541
- The computed value of an expression
540-
- Descriptions
541542
- File location
542543

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

545546
```js
546547
msg(html`Hello <b>${name}</b>`);
547548
msg(html`Hello <b>${this.name}</b>`);
548-
msg(html`Hello <b>${this.name}</b>`, {desc: 'A friendly greeting'});
549549
```
550550

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

557+
Note, while providing a [description](#message-descriptions) does not affect ID
558+
generation, multiple messages with the same ID but different description will
559+
produce an error during analysis to avoid ambiguity in the extracted translation
560+
unit. The following is considered **invalid**:
561+
562+
```js
563+
msg(html`Hello <b>${name}</b>`);
564+
msg(html`Hello <b>${name}</b>`, {desc: 'A friendly greeting'});
565+
```
566+
567+
Make sure that all messages with the same ID also have the same description.
568+
557569
### Overriding IDs
558570

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

packages/lit-dev-content/site/docs/v3/localization/overview.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ Descriptions are represented in XLIFF files using `<note>` elements.
502502
```xml
503503
<trans-unit id="s512957aa09384646">
504504
<source>Launch</source>
505-
<note>Button that begins rocket launch sequence.</note>
505+
<note from="lit-localize">Button that begins rocket launch sequence.</note>
506506
</trans-unit>
507507
```
508508

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

521521
```js
522522
// file1.js
523-
msg('Hello World')
523+
msg('Hello World');
524524

525525
// file2.js
526-
msg('Hello World')
526+
msg('Hello World');
527527
```
528528

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

540540
- The code inside an expression
541541
- The computed value of an expression
542-
- Descriptions
543542
- File location
544543

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

547546
```js
548547
msg(html`Hello <b>${name}</b>`);
549548
msg(html`Hello <b>${this.name}</b>`);
550-
msg(html`Hello <b>${this.name}</b>`, {desc: 'A friendly greeting'});
551549
```
552550

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

557+
Note, while providing a [description](#message-descriptions) does not affect ID
558+
generation, multiple messages with the same ID but different description will
559+
produce an error during analysis to avoid ambiguity in the extracted translation
560+
unit. The following is considered **invalid**:
561+
562+
```js
563+
msg(html`Hello <b>${name}</b>`);
564+
msg(html`Hello <b>${name}</b>`, {desc: 'A friendly greeting'});
565+
```
566+
567+
Make sure that all messages with the same ID also have the same description.
568+
559569
### Overriding IDs
560570

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

0 commit comments

Comments
 (0)