@@ -11,6 +11,11 @@ import {Diagnostics} from '../../../diagnostics';
1111
1212import { ParseAnalysis , ParsedTranslationBundle , TranslationParser } from './translation_parser' ;
1313
14+ interface SimpleJsonFile {
15+ locale : string ;
16+ translations : { [ messageId : string ] : string } ;
17+ }
18+
1419/**
1520 * A translation parser that can parse JSON that has the form:
1621 *
@@ -27,16 +32,16 @@ import {ParseAnalysis, ParsedTranslationBundle, TranslationParser} from './trans
2732 * @see SimpleJsonTranslationSerializer
2833 * @publicApi used by CLI
2934 */
30- export class SimpleJsonTranslationParser implements TranslationParser < Object > {
35+ export class SimpleJsonTranslationParser implements TranslationParser < SimpleJsonFile > {
3136 /**
3237 * @deprecated
3338 */
34- canParse ( filePath : string , contents : string ) : Object | false {
39+ canParse ( filePath : string , contents : string ) : SimpleJsonFile | false {
3540 const result = this . analyze ( filePath , contents ) ;
3641 return result . canParse && result . hint ;
3742 }
3843
39- analyze ( filePath : string , contents : string ) : ParseAnalysis < Object > {
44+ analyze ( filePath : string , contents : string ) : ParseAnalysis < SimpleJsonFile > {
4045 const diagnostics = new Diagnostics ( ) ;
4146 // For this to be parsable, the extension must be `.json` and the contents must include "locale"
4247 // and "translations" keys.
@@ -46,7 +51,7 @@ export class SimpleJsonTranslationParser implements TranslationParser<Object> {
4651 return { canParse : false , diagnostics} ;
4752 }
4853 try {
49- const json = JSON . parse ( contents ) ;
54+ const json = JSON . parse ( contents ) as SimpleJsonFile ;
5055 if ( json . locale === undefined ) {
5156 diagnostics . warn ( 'Required "locale" property missing.' ) ;
5257 return { canParse : false , diagnostics} ;
@@ -70,8 +75,8 @@ export class SimpleJsonTranslationParser implements TranslationParser<Object> {
7075 }
7176 }
7277
73- parse ( _filePath : string , contents : string , json ?: Object ) : ParsedTranslationBundle {
74- const { locale : parsedLocale , translations} = json || JSON . parse ( contents ) ;
78+ parse ( _filePath : string , contents : string , json ?: SimpleJsonFile ) : ParsedTranslationBundle {
79+ const { locale : parsedLocale , translations} = json || JSON . parse ( contents ) as SimpleJsonFile ;
7580 const parsedTranslations : Record < ɵMessageId , ɵParsedTranslation > = { } ;
7681 for ( const messageId in translations ) {
7782 const targetMessage = translations [ messageId ] ;
0 commit comments