Skip to content

Commit

Permalink
feat(@angular-devkit/build-angular): expose legacy-migrate message fo…
Browse files Browse the repository at this point in the history
…rmat

We recently added a new message format called `legacy-extract` that is used to migrate between
legacy and canonical message IDs (see angular/angular#41026).

These changes expose the new format in `extract-i18n`.
  • Loading branch information
crisbeto authored and alan-agius4 committed Mar 17, 2021
1 parent d37f731 commit 1525e7a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 12 additions & 2 deletions packages/angular_devkit/build_angular/src/extract-i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { BuildResult, runWebpack } from '@angular-devkit/build-webpack';
import { JsonObject } from '@angular-devkit/core';
import type { ɵParsedMessage as LocalizeMessage } from '@angular/localize';
import type { Diagnostics } from '@angular/localize/src/tools/src/diagnostics';
import * as fs from 'fs';
import * as path from 'path';
import * as webpack from 'webpack';
Expand All @@ -38,6 +39,7 @@ function getI18nOutfile(format: string | undefined) {
case 'xliff2':
return 'messages.xlf';
case 'json':
case 'legacy-migrate':
return 'messages.json';
case 'arb':
return 'messages.arb';
Expand All @@ -46,7 +48,7 @@ function getI18nOutfile(format: string | undefined) {
}
}

async function getSerializer(format: Format, sourceLocale: string, basePath: string, useLegacyIds: boolean) {
async function getSerializer(format: Format, sourceLocale: string, basePath: string, useLegacyIds: boolean, diagnostics: Diagnostics) {
switch (format) {
case Format.Xmb:
const { XmbTranslationSerializer } =
Expand All @@ -73,8 +75,12 @@ async function getSerializer(format: Format, sourceLocale: string, basePath: str
const { SimpleJsonTranslationSerializer } =
await import('@angular/localize/src/tools/src/extract/translation_files/json_translation_serializer');

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

return new LegacyMessageIdMigrationSerializer(diagnostics);
case Format.Arb:
const { ArbTranslationSerializer } =
await import('@angular/localize/src/tools/src/extract/translation_files/arb_translation_serializer');
Expand Down Expand Up @@ -114,6 +120,9 @@ function normalizeFormatOption(options: ExtractI18nBuilderOptions) {
case Format.Arb:
format = Format.Arb;
break;
case Format.LegacyMigrate:
format = Format.LegacyMigrate;
break;
case undefined:
format = Format.Xlf;
break;
Expand Down Expand Up @@ -311,6 +320,7 @@ export async function execute(
i18n.sourceLocale,
basePath,
useLegacyIds,
diagnostics,
);
const content = serializer.serialize(ivyMessages);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"xlf2",
"xliff2",
"json",
"arb"
"arb",
"legacy-migrate"
]
},
"i18nFormat": {
Expand All @@ -37,7 +38,8 @@
"xlf2",
"xliff2",
"json",
"arb"
"arb",
"legacy-migrate"
]
},
"i18nLocale": {
Expand Down

0 comments on commit 1525e7a

Please sign in to comment.