-
Notifications
You must be signed in to change notification settings - Fork 24.8k
/
simple_json_translation_parser.ts
37 lines (35 loc) 路 1.23 KB
/
simple_json_translation_parser.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
/**
* @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 {傻MessageId, 傻ParsedTranslation, 傻parseTranslation} from '@angular/localize';
import {extname} from 'path';
import {ParsedTranslationBundle, TranslationParser} from '../translation_parser';
/**
* A translation parser that can parse JSON that has the form:
*
* ```
* {
* "locale": "...",
* "translations": {
* "message-id": "Target message string",
* ...
* }
* }
* ```
*/
export class SimpleJsonTranslationParser implements TranslationParser {
canParse(filePath: string, _contents: string): boolean { return (extname(filePath) === '.json'); }
parse(_filePath: string, contents: string): ParsedTranslationBundle {
const {locale: parsedLocale, translations} = JSON.parse(contents);
const parsedTranslations: Record<傻MessageId, 傻ParsedTranslation> = {};
for (const messageId in translations) {
const targetMessage = translations[messageId];
parsedTranslations[messageId] = 傻parseTranslation(targetMessage);
}
return {locale: parsedLocale, translations: parsedTranslations};
}
}