/
xliff1_translation_serializer_spec.ts
123 lines (120 loc) 路 6.27 KB
/
xliff1_translation_serializer_spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {absoluteFrom} from '@angular/compiler-cli/src/ngtsc/file_system';
import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing';
import {傻ParsedMessage, 傻SourceLocation} from '@angular/localize';
import {Xliff1TranslationSerializer} from '../../../src/extract/translation_files/xliff1_translation_serializer';
import {mockMessage} from './mock_message';
runInEachFileSystem(() => {
describe('Xliff1TranslationSerializer', () => {
[false, true].forEach(useLegacyIds => {
describe(`renderFile() [using ${useLegacyIds ? 'legacy' : 'canonical'} ids]`, () => {
it('should convert a set of parsed messages into an XML string', () => {
const phLocation: 傻SourceLocation = {
start: {line: 0, column: 10},
end: {line: 1, column: 15},
file: absoluteFrom('/project/file.ts'),
text: 'placeholder + 1'
};
const messagePartLocation: 傻SourceLocation = {
start: {line: 0, column: 5},
end: {line: 0, column: 10},
file: absoluteFrom('/project/file.ts'),
text: 'message part'
};
const messages: 傻ParsedMessage[] = [
mockMessage('12345', ['a', 'b', 'c'], ['PH', 'PH_1'], {
meaning: 'some meaning',
location: {
file: absoluteFrom('/project/file.ts'),
start: {line: 5, column: 10},
end: {line: 5, column: 12}
},
legacyIds: ['1234567890ABCDEF1234567890ABCDEF12345678', '615790887472569365'],
}),
mockMessage('54321', ['a', 'b', 'c'], ['PH', 'PH_1'], {
customId: 'someId',
legacyIds: ['87654321FEDCBA0987654321FEDCBA0987654321', '563965274788097516'],
messagePartLocations: [undefined, messagePartLocation, undefined],
substitutionLocations: {'PH': phLocation, 'PH_1': undefined},
}),
mockMessage(
'67890', ['a', '', 'c'], ['START_TAG_SPAN', 'CLOSE_TAG_SPAN'],
{description: 'some description'}),
mockMessage('13579', ['', 'b', ''], ['START_BOLD_TEXT', 'CLOSE_BOLD_TEXT'], {}),
mockMessage('24680', ['a'], [], {meaning: 'meaning', description: 'and description'}),
mockMessage('80808', ['multi\nlines'], [], {}),
mockMessage('90000', ['<escape', 'me>'], ['double-quotes-"'], {}),
mockMessage(
'100000',
[
'pre-ICU {VAR_SELECT, select, a {a} b {{INTERPOLATION}} c {pre {INTERPOLATION_1} post}} post-ICU'
],
[], {}),
mockMessage(
'100001',
[
'{VAR_PLURAL, plural, one {{START_BOLD_TEXT}something bold{CLOSE_BOLD_TEXT}} other {pre {START_TAG_SPAN}middle{CLOSE_TAG_SPAN} post}}'
],
[], {}),
];
const serializer =
new Xliff1TranslationSerializer('xx', absoluteFrom('/project'), useLegacyIds);
const output = serializer.serialize(messages);
expect(output).toEqual([
`<?xml version="1.0" encoding="UTF-8" ?>`,
`<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">`,
` <file source-language="xx" datatype="plaintext" original="ng2.template">`,
` <body>`,
` <trans-unit id="${
useLegacyIds ? '1234567890ABCDEF1234567890ABCDEF12345678' :
'12345'}" datatype="html">`,
` <source xml:space="preserve">a<x id="PH"/>b<x id="PH_1"/>c</source>`,
` <context-group purpose="location">`,
` <context context-type="sourcefile">file.ts</context>`,
` <context context-type="linenumber">6</context>`,
` </context-group>`,
` <note priority="1" from="meaning">some meaning</note>`,
` </trans-unit>`,
` <trans-unit id="someId" datatype="html">`,
` <source xml:space="preserve">a<x id="PH" equiv-text="placeholder + 1"/>b<x id="PH_1"/>c</source>`,
` </trans-unit>`,
` <trans-unit id="67890" datatype="html">`,
` <source xml:space="preserve">a<x id="START_TAG_SPAN"/><x id="CLOSE_TAG_SPAN"/>c</source>`,
` <note priority="1" from="description">some description</note>`,
` </trans-unit>`,
` <trans-unit id="13579" datatype="html">`,
` <source xml:space="preserve"><x id="START_BOLD_TEXT"/>b<x id="CLOSE_BOLD_TEXT"/></source>`,
` </trans-unit>`,
` <trans-unit id="24680" datatype="html">`,
` <source xml:space="preserve">a</source>`,
` <note priority="1" from="description">and description</note>`,
` <note priority="1" from="meaning">meaning</note>`,
` </trans-unit>`,
` <trans-unit id="80808" datatype="html">`,
` <source xml:space="preserve">multi`,
`lines</source>`,
` </trans-unit>`,
` <trans-unit id="90000" datatype="html">`,
` <source xml:space="preserve"><escape<x id="double-quotes-""/>me></source>`,
` </trans-unit>`,
` <trans-unit id="100000" datatype="html">`,
` <source xml:space="preserve">pre-ICU {VAR_SELECT, select, a {a} b {<x id="INTERPOLATION"/>} c {pre <x id="INTERPOLATION_1"/> post}} post-ICU</source>`,
` </trans-unit>`,
` <trans-unit id="100001" datatype="html">`,
` <source xml:space="preserve">{VAR_PLURAL, plural, one {<x id="START_BOLD_TEXT"/>something bold<x id="CLOSE_BOLD_TEXT"/>} other {pre <x id="START_TAG_SPAN"/>middle<x id="CLOSE_TAG_SPAN"/> post}}</source>`,
` </trans-unit>`,
` </body>`,
` </file>`,
`</xliff>\n`,
].join('\n'));
});
});
});
});
});