-
Notifications
You must be signed in to change notification settings - Fork 24.8k
/
arb_translation_parser_spec.ts
53 lines (49 loc) 路 1.94 KB
/
arb_translation_parser_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
/**
* @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 {傻makeTemplateObject} from '@angular/localize';
import {ArbTranslationParser} from '../../../../src/translate/translation_files/translation_parsers/arb_translation_parser';
describe('SimpleArbTranslationParser', () => {
describe('analyze()', () => {
it('should return true if the file extension is `.json` and contains `@@locale` property',
() => {
const parser = new ArbTranslationParser();
expect(parser.analyze('/some/file.xlf', '').canParse).toBeFalse();
expect(parser.analyze('/some/file.json', 'xxx').canParse).toBeFalse();
expect(parser.analyze('/some/file.json', '{ "someKey": "someValue" }').canParse)
.toBeFalse();
expect(parser.analyze('/some/file.json', '{ "@@locale": "en", "someKey": "someValue" }')
.canParse)
.toBeTrue();
});
});
describe('parse()', () => {
it('should extract the locale from the JSON contents', () => {
const parser = new ArbTranslationParser();
const result = parser.parse('/some/file.json', '{"@@locale": "en"}');
expect(result.locale).toEqual('en');
});
it('should extract and process the translations from the JSON contents', () => {
const parser = new ArbTranslationParser();
const result = parser.parse('/some/file.json', `{
"@@locale": "fr",
"customId": "Bonjour, {$ph_1}!",
"@customId": {
"type": "text",
"description": "Some description"
}
}`);
expect(result.translations).toEqual({
'customId': {
text: 'Bonjour, {$ph_1}!',
messageParts: 傻makeTemplateObject(['Bonjour, ', '!'], ['Bonjour, ', '!']),
placeholderNames: ['ph_1'],
},
});
});
});
});