@@ -10,20 +10,7 @@ import * as fs from 'fs';
10
10
export type TranslationLoader = ( path : string ) => { translation : unknown ; format : string } ;
11
11
12
12
export async function createTranslationLoader ( ) : Promise < TranslationLoader > {
13
- const parsers = {
14
- json : new ( await import (
15
- // tslint:disable-next-line:trailing-comma
16
- '@angular/localize/src/tools/src/translate/translation_files/translation_parsers/simple_json/simple_json_translation_parser'
17
- ) ) . SimpleJsonTranslationParser ( ) ,
18
- xlf : new ( await import (
19
- // tslint:disable-next-line:trailing-comma
20
- '@angular/localize/src/tools/src/translate/translation_files/translation_parsers/xliff1/xliff1_translation_parser'
21
- ) ) . Xliff1TranslationParser ( ) ,
22
- xlf2 : new ( await import (
23
- // tslint:disable-next-line:trailing-comma
24
- '@angular/localize/src/tools/src/translate/translation_files/translation_parsers/xliff2/xliff2_translation_parser'
25
- ) ) . Xliff2TranslationParser ( ) ,
26
- } ;
13
+ const parsers = await importParsers ( ) ;
27
14
28
15
return ( path : string ) => {
29
16
const content = fs . readFileSync ( path , 'utf8' ) ;
@@ -37,3 +24,40 @@ export async function createTranslationLoader(): Promise<TranslationLoader> {
37
24
throw new Error ( 'Unsupported translation file format.' ) ;
38
25
} ;
39
26
}
27
+
28
+ async function importParsers ( ) {
29
+ try {
30
+ return {
31
+ json : new ( await import (
32
+ // tslint:disable-next-line:trailing-comma
33
+ '@angular/localize/src/tools/src/translate/translation_files/translation_parsers/simple_json/simple_json_translation_parser'
34
+ ) ) . SimpleJsonTranslationParser ( ) ,
35
+ xlf : new ( await import (
36
+ // tslint:disable-next-line:trailing-comma
37
+ '@angular/localize/src/tools/src/translate/translation_files/translation_parsers/xliff1/xliff1_translation_parser'
38
+ ) ) . Xliff1TranslationParser ( ) ,
39
+ xlf2 : new ( await import (
40
+ // tslint:disable-next-line:trailing-comma
41
+ '@angular/localize/src/tools/src/translate/translation_files/translation_parsers/xliff2/xliff2_translation_parser'
42
+ ) ) . Xliff2TranslationParser ( ) ,
43
+ } ;
44
+ } catch {
45
+ return {
46
+ json : new ( await import (
47
+ // @ts -ignore
48
+ // tslint:disable-next-line:trailing-comma
49
+ '@angular/localize/src/tools/src/translate/translation_files/translation_parsers/simple_json_translation_parser'
50
+ ) ) . SimpleJsonTranslationParser ( ) ,
51
+ xlf : new ( await import (
52
+ // @ts -ignore
53
+ // tslint:disable-next-line:trailing-comma
54
+ '@angular/localize/src/tools/src/translate/translation_files/translation_parsers/xliff1_translation_parser'
55
+ ) ) . Xliff1TranslationParser ( ) ,
56
+ xlf2 : new ( await import (
57
+ // @ts -ignore
58
+ // tslint:disable-next-line:trailing-comma
59
+ '@angular/localize/src/tools/src/translate/translation_files/translation_parsers/xliff2_translation_parser'
60
+ ) ) . Xliff2TranslationParser ( ) ,
61
+ } ;
62
+ }
63
+ }
0 commit comments