-
Notifications
You must be signed in to change notification settings - Fork 24.8k
/
simple_json_spec.ts
43 lines (40 loc) 路 1.57 KB
/
simple_json_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
/**
* @license
* Copyright Google Inc. 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 {SimpleJsonTranslationParser} from '../../../../src/translate/translation_files/translation_parsers/simple_json_translation_parser';
describe('SimpleJsonTranslationParser', () => {
describe('canParse()', () => {
it('should return true if the file extension is `.json`', () => {
const parser = new SimpleJsonTranslationParser();
expect(parser.canParse('/some/file.xlf', '')).toBe(false);
expect(parser.canParse('/some/file.json', '')).toBe(true);
});
});
describe('parse()', () => {
it('should extract the locale from the JSON contents', () => {
const parser = new SimpleJsonTranslationParser();
const result = parser.parse('/some/file.json', '{"locale": "en", "translations": {}}');
expect(result.locale).toEqual('en');
});
it('should extract and process the translations from the JSON contents', () => {
const parser = new SimpleJsonTranslationParser();
const result = parser.parse('/some/file.json', `{
"locale": "fr",
"translations": {
"Hello, {$ph_1}!": "Bonjour, {$ph_1}!"
}
}`);
expect(result.translations).toEqual({
'Hello, {$ph_1}!': {
messageParts: 傻makeTemplateObject(['Bonjour, ', '!'], ['Bonjour, ', '!']),
placeholderNames: ['ph_1']
},
});
});
});
});