Skip to content

Commit

Permalink
feat(@angular-devkit/build-angular): support extracting and merging w…
Browse files Browse the repository at this point in the history
…ith arb format
  • Loading branch information
wenqi73 authored and alan-agius4 committed Jan 8, 2021
1 parent dc97667 commit ab72f8d
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/angular/cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,8 @@
"xliff",
"xlf2",
"xliff2",
"json"
"json",
"arb"
]
},
"i18nFormat": {
Expand All @@ -1419,7 +1420,8 @@
"xliff",
"xlf2",
"xliff2",
"json"
"json",
"arb"
]
},
"i18nLocale": {
Expand Down
17 changes: 17 additions & 0 deletions packages/angular_devkit/build_angular/src/extract-i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ function getI18nOutfile(format: string | undefined) {
return 'messages.xlf';
case 'json':
return 'messages.json';
case 'arb':
return 'messages.arb';
default:
throw new Error(`Unsupported format "${format}"`);
}
Expand Down Expand Up @@ -73,6 +75,18 @@ async function getSerializer(format: Format, sourceLocale: string, basePath: str

// tslint:disable-next-line: no-any
return new SimpleJsonTranslationSerializer(sourceLocale);
case Format.Arb:
const { ArbTranslationSerializer } =
await import('@angular/localize/src/tools/src/extract/translation_files/arb_translation_serializer');

const fileSystem = {
relative(from: string, to: string): string {
return path.relative(from, to);
},
};

// tslint:disable-next-line: no-any
return new ArbTranslationSerializer(sourceLocale, basePath as any, fileSystem as any);
}
}

Expand All @@ -97,6 +111,9 @@ function normalizeFormatOption(options: ExtractI18nBuilderOptions) {
case Format.Json:
format = Format.Json;
break;
case Format.Arb:
format = Format.Arb;
break;
case undefined:
format = Format.Xlf;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"xliff",
"xlf2",
"xliff2",
"json"
"json",
"arb"
]
},
"i18nFormat": {
Expand All @@ -35,7 +36,8 @@
"xliff",
"xlf2",
"xliff2",
"json"
"json",
"arb"
]
},
"i18nLocale": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ async function importParsers() {
const diagnostics = new localizeDiag.Diagnostics();

const parsers = {
arb: new (await import(
// tslint:disable-next-line:trailing-comma
'@angular/localize/src/tools/src/translate/translation_files/translation_parsers/arb_translation_parser'
)).ArbTranslationParser(),
json: new (await import(
// tslint:disable-next-line:trailing-comma
'@angular/localize/src/tools/src/translate/translation_files/translation_parsers/simple_json_translation_parser'
Expand Down
10 changes: 10 additions & 0 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-dl-arb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { executeTest } from './ivy-localize-dl-xliff2';
import { setupI18nConfig } from './legacy';

export default async function() {
// Setup i18n tests and config.
await setupI18nConfig(true, 'arb');

// Execute the tests
await executeTest();
}
6 changes: 6 additions & 0 deletions tests/legacy-cli/e2e/tests/i18n/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ export const formats = {
sourceCheck: '"locale": "en-US"',
replacements: [
],
},
'arb': {
ext: 'arb',
sourceCheck: '"@@locale": "en-US"',
replacements: [
],
}
};

Expand Down

0 comments on commit ab72f8d

Please sign in to comment.