Skip to content

Commit

Permalink
fix(localize): include meaning in generated ARB files (#40546)
Browse files Browse the repository at this point in the history
The ARB format doesn't have a dedicated field for message meaning so these changes include it
as a customize attribute called `x-meaning`.

Fixes #40506.

PR Close #40546
  • Loading branch information
crisbeto authored and thePunderWoman committed Jan 25, 2021
1 parent 760557b commit 5661298
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Expand Up @@ -50,7 +50,8 @@ export class ArbTranslationSerializer implements TranslationSerializer {
const id = getMessageId(message);
output += this.serializeMessage(id, message);
output += this.serializeMeta(
id, message.description, duplicateMessages.filter(hasLocation).map(m => m.location));
id, message.description, message.meaning,
duplicateMessages.filter(hasLocation).map(m => m.location));
}

output += '\n}';
Expand All @@ -62,14 +63,19 @@ export class ArbTranslationSerializer implements TranslationSerializer {
return `,\n ${JSON.stringify(id)}: ${JSON.stringify(message.text)}`;
}

private serializeMeta(id: string, description: string|undefined, locations: ɵSourceLocation[]):
string {
private serializeMeta(
id: string, description: string|undefined, meaning: string|undefined,
locations: ɵSourceLocation[]): string {
const meta: string[] = [];

if (description) {
meta.push(`\n "description": ${JSON.stringify(description)}`);
}

if (meaning) {
meta.push(`\n "x-meaning": ${JSON.stringify(meaning)}`);
}

if (locations.length > 0) {
let locationStr = `\n "x-locations": [`;
for (let i = 0; i < locations.length; i++) {
Expand Down
Expand Up @@ -64,14 +64,16 @@ runInEachFileSystem(() => {
' "13579": "{$START_BOLD_TEXT}b{$CLOSE_BOLD_TEXT}",',
' "24680": "a",',
' "@24680": {',
' "description": "and description"',
' "description": "and description",',
' "x-meaning": "meaning"',
' },',
' "80808": "multi\\nlines",',
' "90000": "<escape{$double-quotes-\\"}me>",',
' "100000": "pre-ICU {VAR_SELECT, select, a {a} b {{INTERPOLATION}} c {pre {INTERPOLATION_1} post}} post-ICU",',
' "100001": "{VAR_PLURAL, plural, one {{START_BOLD_TEXT}something bold{CLOSE_BOLD_TEXT}} other {pre {START_TAG_SPAN}middle{CLOSE_TAG_SPAN} post}}",',
' "12345": "a{$PH}b{$PH_1}c",',
' "@12345": {',
' "x-meaning": "some meaning",',
' "x-locations": [',
' {',
' "file": "file.ts",',
Expand Down

0 comments on commit 5661298

Please sign in to comment.