fix(localize): include meaning in generated ARB files (#40546)

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
This commit is contained in:
Kristiyan Kostadinov 2021-01-24 08:56:21 +01:00 committed by Jessica Janiuk
parent 6db342a87a
commit 8b9f6b504e
2 changed files with 12 additions and 4 deletions

View File

@ -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}';
@ -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++) {

View File

@ -64,7 +64,8 @@ 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>",',
@ -72,6 +73,7 @@ runInEachFileSystem(() => {
' "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",',