feat(i18n): pass translation config directly into ngc (#10622)
This commit is contained in:
parent
04c6b2fe85
commit
6580d67875
|
@ -2,3 +2,4 @@
|
|||
<form><input type="button" [(ngModel)]="ctxProp" name="first"/></form>
|
||||
<my-comp *ngIf="ctxBool"></my-comp>
|
||||
<div *ngFor="let x of ctxArr" [attr.value]="x"></div>
|
||||
<p id="welcomeMessage"><!--i18n-->Welcome<!--/i18n--></p>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
import {NgFor, NgIf} from '@angular/common';
|
||||
import {Component, Inject} from '@angular/core';
|
||||
import {Component, Inject, LOCALE_ID, TRANSLATIONS_FORMAT} from '@angular/core';
|
||||
import {FORM_DIRECTIVES} from '@angular/forms';
|
||||
|
||||
import {MultipleComponentsMyComp} from './a/multiple_components';
|
||||
|
@ -23,5 +23,9 @@ export class BasicComp {
|
|||
ctxProp: string;
|
||||
ctxBool: boolean;
|
||||
ctxArr: any[] = [];
|
||||
constructor() { this.ctxProp = 'initialValue'; }
|
||||
constructor(
|
||||
@Inject(LOCALE_ID) public localeId: string,
|
||||
@Inject(TRANSLATIONS_FORMAT) public translationsFormat: string) {
|
||||
this.ctxProp = 'initialValue';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
<translationbundle>
|
||||
<translation id="76e1eccb1b772fa9f294ef9c146ea6d0efa8a2d4">käännä teksti</translation>
|
||||
<translation id="65cc4ab3b4c438e07c89be2b677d08369fb62da2">tervetuloa</translation>
|
||||
</translationbundle>
|
|
@ -44,24 +44,45 @@ describe('template codegen output', () => {
|
|||
it('should support ngIf', () => {
|
||||
var compFixture = createComponent(BasicComp);
|
||||
var debugElement = compFixture.debugElement;
|
||||
expect(debugElement.children.length).toBe(2);
|
||||
expect(debugElement.children.length).toBe(3);
|
||||
|
||||
compFixture.componentInstance.ctxBool = true;
|
||||
compFixture.detectChanges();
|
||||
expect(debugElement.children.length).toBe(3);
|
||||
expect(debugElement.children.length).toBe(4);
|
||||
expect(debugElement.children[2].injector.get(MultipleComponentsMyComp)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should support ngFor', () => {
|
||||
var compFixture = createComponent(BasicComp);
|
||||
var debugElement = compFixture.debugElement;
|
||||
expect(debugElement.children.length).toBe(2);
|
||||
expect(debugElement.children.length).toBe(3);
|
||||
|
||||
// test NgFor
|
||||
compFixture.componentInstance.ctxArr = [1, 2];
|
||||
compFixture.detectChanges();
|
||||
expect(debugElement.children.length).toBe(4);
|
||||
expect(debugElement.children.length).toBe(5);
|
||||
expect(debugElement.children[2].attributes['value']).toBe('1');
|
||||
expect(debugElement.children[3].attributes['value']).toBe('2');
|
||||
});
|
||||
|
||||
describe('i18n', () => {
|
||||
it('should inject the locale into the component', () => {
|
||||
const compFixture = createComponent(BasicComp);
|
||||
expect(compFixture.componentInstance.localeId).toEqual('fi');
|
||||
});
|
||||
|
||||
it('should inject the translations format into the component', () => {
|
||||
const compFixture = createComponent(BasicComp);
|
||||
expect(compFixture.componentInstance.translationsFormat).toEqual('xtb');
|
||||
});
|
||||
|
||||
it('should support i18n for content tags', () => {
|
||||
const compFixture = createComponent(BasicComp);
|
||||
const debugElement = compFixture.debugElement;
|
||||
const containerElement = <any>debugElement.nativeElement;
|
||||
const pElement = <any>containerElement.children.find((c: any) => c.name == 'p');
|
||||
const pText = <string>pElement.children.map((c: any) => c.data).join('').trim();
|
||||
expect(pText).toBe('tervetuloa');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -39,6 +39,7 @@ describe('template i18n extraction output', () => {
|
|||
]>
|
||||
<messagebundle>
|
||||
<msg id="76e1eccb1b772fa9f294ef9c146ea6d0efa8a2d4" desc="desc" meaning="meaning">translate me</msg>
|
||||
<msg id="65cc4ab3b4c438e07c89be2b677d08369fb62da2">Welcome</msg>
|
||||
</messagebundle>`;
|
||||
|
||||
const xmbOutput = path.join(outDir, 'messages.xmb');
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
*/
|
||||
import * as compiler from '@angular/compiler';
|
||||
import {ComponentMetadata, NgModuleMetadata, ViewEncapsulation} from '@angular/core';
|
||||
import {AngularCompilerOptions} from '@angular/tsc-wrapped';
|
||||
import {AngularCompilerOptions, NgcCliOptions} from '@angular/tsc-wrapped';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
|
@ -22,6 +22,8 @@ import {GENERATED_FILES, ReflectorHost, ReflectorHostContext} from './reflector_
|
|||
import {StaticAndDynamicReflectionCapabilities} from './static_reflection_capabilities';
|
||||
import {StaticReflector, StaticSymbol} from './static_reflector';
|
||||
|
||||
const nodeFs = require('fs');
|
||||
|
||||
const PREAMBLE = `/**
|
||||
* This file is generated by the Angular 2 template compiler.
|
||||
* Do not edit.
|
||||
|
@ -117,8 +119,9 @@ export class CodeGenerator {
|
|||
}
|
||||
|
||||
static create(
|
||||
options: AngularCompilerOptions, program: ts.Program, compilerHost: ts.CompilerHost,
|
||||
reflectorHostContext?: ReflectorHostContext, xhr?: compiler.XHR): CodeGenerator {
|
||||
options: AngularCompilerOptions, cliOptions: NgcCliOptions, program: ts.Program,
|
||||
compilerHost: ts.CompilerHost, reflectorHostContext?: ReflectorHostContext,
|
||||
xhr?: compiler.XHR): CodeGenerator {
|
||||
xhr = xhr || {
|
||||
get: (s: string) => {
|
||||
if (!compilerHost.fileExists(s)) {
|
||||
|
@ -128,11 +131,18 @@ export class CodeGenerator {
|
|||
return Promise.resolve(compilerHost.readFile(s));
|
||||
}
|
||||
};
|
||||
const transFile = cliOptions.i18nFile;
|
||||
const locale = cliOptions.locale;
|
||||
let transContent: string = '';
|
||||
if (transFile && locale) {
|
||||
transContent = nodeFs.readFileSync(transFile, 'utf8');
|
||||
}
|
||||
|
||||
const urlResolver: compiler.UrlResolver = compiler.createOfflineCompileUrlResolver();
|
||||
const reflectorHost = new ReflectorHost(program, compilerHost, options, reflectorHostContext);
|
||||
const staticReflector = new StaticReflector(reflectorHost);
|
||||
StaticAndDynamicReflectionCapabilities.install(staticReflector);
|
||||
const htmlParser = new compiler.i18n.HtmlParser(new HtmlParser());
|
||||
const htmlParser = new compiler.i18n.HtmlParser(new HtmlParser(), transContent);
|
||||
const config = new compiler.CompilerConfig({
|
||||
genDebugInfo: options.debug === true,
|
||||
defaultEncapsulation: ViewEncapsulation.Emulated,
|
||||
|
@ -151,7 +161,8 @@ export class CodeGenerator {
|
|||
config, console, elementSchemaRegistry, staticReflector);
|
||||
const offlineCompiler = new compiler.OfflineCompiler(
|
||||
resolver, normalizer, tmplParser, new StyleCompiler(urlResolver), new ViewCompiler(config),
|
||||
new NgModuleCompiler(), new TypeScriptEmitter(reflectorHost));
|
||||
new NgModuleCompiler(), new TypeScriptEmitter(reflectorHost), cliOptions.locale,
|
||||
cliOptions.i18nFormat);
|
||||
|
||||
return new CodeGenerator(
|
||||
options, program, compilerHost, staticReflector, offlineCompiler, reflectorHost);
|
||||
|
|
|
@ -28,8 +28,9 @@ import {StaticAndDynamicReflectionCapabilities} from './static_reflection_capabi
|
|||
import {StaticReflector, StaticSymbol} from './static_reflector';
|
||||
|
||||
function extract(
|
||||
ngOptions: tsc.AngularCompilerOptions, program: ts.Program, host: ts.CompilerHost) {
|
||||
const extractor = Extractor.create(ngOptions, program, host);
|
||||
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.I18nExtractionCliOptions,
|
||||
program: ts.Program, host: ts.CompilerHost) {
|
||||
const extractor = Extractor.create(ngOptions, cliOptions.i18nFormat, program, host);
|
||||
const bundlePromise: Promise<compiler.i18n.MessageBundle> = extractor.extract();
|
||||
|
||||
return (bundlePromise).then(messageBundle => {
|
||||
|
@ -126,8 +127,8 @@ export class Extractor {
|
|||
}
|
||||
|
||||
static create(
|
||||
options: tsc.AngularCompilerOptions, program: ts.Program, compilerHost: ts.CompilerHost,
|
||||
reflectorHostContext?: ReflectorHostContext): Extractor {
|
||||
options: tsc.AngularCompilerOptions, translationsFormat: string, program: ts.Program,
|
||||
compilerHost: ts.CompilerHost, reflectorHostContext?: ReflectorHostContext): Extractor {
|
||||
const xhr: compiler.XHR = {
|
||||
get: (s: string) => {
|
||||
if (!compilerHost.fileExists(s)) {
|
||||
|
@ -163,7 +164,7 @@ export class Extractor {
|
|||
config, console, elementSchemaRegistry, staticReflector);
|
||||
const offlineCompiler = new compiler.OfflineCompiler(
|
||||
resolver, normalizer, tmplParser, new StyleCompiler(urlResolver), new ViewCompiler(config),
|
||||
new NgModuleCompiler(), new TypeScriptEmitter(reflectorHost));
|
||||
new NgModuleCompiler(), new TypeScriptEmitter(reflectorHost), null, null);
|
||||
|
||||
// TODO(vicb): implicit tags & attributes
|
||||
let messageBundle = new compiler.i18n.MessageBundle(htmlParser, [], {});
|
||||
|
@ -183,11 +184,13 @@ interface FileMetadata {
|
|||
// Entry point
|
||||
if (require.main === module) {
|
||||
const args = require('minimist')(process.argv.slice(2));
|
||||
tsc.main(args.p || args.project || '.', args.basePath, extract)
|
||||
.then(exitCode => process.exit(exitCode))
|
||||
.catch(e => {
|
||||
const project = args.p || args.project || '.';
|
||||
const cliOptions = new tsc.I18nExtractionCliOptions(args);
|
||||
tsc.main(project, cliOptions, extract)
|
||||
.then((exitCode: any) => process.exit(exitCode))
|
||||
.catch((e: any) => {
|
||||
console.error(e.stack);
|
||||
console.error('Extraction failed');
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,18 +17,19 @@ import * as tsc from '@angular/tsc-wrapped';
|
|||
import {CodeGenerator} from './codegen';
|
||||
|
||||
function codegen(
|
||||
ngOptions: tsc.AngularCompilerOptions, program: ts.Program, host: ts.CompilerHost) {
|
||||
return CodeGenerator.create(ngOptions, program, host).codegen();
|
||||
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.NgcCliOptions, program: ts.Program,
|
||||
host: ts.CompilerHost) {
|
||||
return CodeGenerator.create(ngOptions, cliOptions, program, host).codegen();
|
||||
}
|
||||
|
||||
// CLI entry point
|
||||
if (require.main === module) {
|
||||
const args = require('minimist')(process.argv.slice(2));
|
||||
tsc.main(args.p || args.project || '.', args.basePath, codegen)
|
||||
.then(exitCode => process.exit(exitCode))
|
||||
.catch(e => {
|
||||
console.error(e.stack);
|
||||
console.error('Compilation failed');
|
||||
process.exit(1);
|
||||
});
|
||||
const project = args.p || args.project || '.';
|
||||
const cliOptions = new tsc.NgcCliOptions(args);
|
||||
tsc.main(project, cliOptions, codegen).then(exitCode => process.exit(exitCode)).catch(e => {
|
||||
console.error(e.stack);
|
||||
console.error('Compilation failed');
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {COMPILER_OPTIONS, Compiler, CompilerFactory, CompilerOptions, Component, Inject, Injectable, OptionalMetadata, PLATFORM_DIRECTIVES, PLATFORM_INITIALIZER, PLATFORM_PIPES, PlatformRef, Provider, ReflectiveInjector, Type, ViewEncapsulation, createPlatformFactory, isDevMode, platformCore} from '@angular/core';
|
||||
import {COMPILER_OPTIONS, Compiler, CompilerFactory, CompilerOptions, Component, Inject, Injectable, OptionalMetadata, PLATFORM_DIRECTIVES, PLATFORM_INITIALIZER, PLATFORM_PIPES, PlatformRef, Provider, ReflectiveInjector, TRANSLATIONS, Type, ViewEncapsulation, createPlatformFactory, isDevMode, platformCore} from '@angular/core';
|
||||
|
||||
export * from './template_parser/template_ast';
|
||||
export {TEMPLATE_TRANSFORMS} from './template_parser/template_parser';
|
||||
|
@ -65,7 +65,7 @@ export const COMPILER_PROVIDERS: Array<any|Type<any>|{[k: string]: any}|any[]> =
|
|||
provide: i18n.HtmlParser,
|
||||
useFactory: (parser: HtmlParser, translations: string) =>
|
||||
new i18n.HtmlParser(parser, translations),
|
||||
deps: [HtmlParser, [new OptionalMetadata(), new Inject(i18n.TRANSLATIONS)]]
|
||||
deps: [HtmlParser, [new OptionalMetadata(), new Inject(TRANSLATIONS)]]
|
||||
},
|
||||
TemplateParser,
|
||||
DirectiveNormalizer,
|
||||
|
|
|
@ -6,12 +6,8 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {OpaqueToken} from '@angular/core';
|
||||
|
||||
export {HtmlParser} from './html_parser';
|
||||
export {MessageBundle} from './message_bundle';
|
||||
export {Serializer} from './serializers/serializer';
|
||||
export {Xmb} from './serializers/xmb';
|
||||
export {Xtb} from './serializers/xtb';
|
||||
|
||||
export const TRANSLATIONS = new OpaqueToken('Translations');
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ElementRef, Injector, NgModuleFactory, QueryList, RenderComponentType, Renderer, SecurityContext, SimpleChange, TemplateRef, ViewContainerRef, ViewEncapsulation} from '@angular/core';
|
||||
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ElementRef, Injector, LOCALE_ID as LOCALE_ID_, NgModuleFactory, QueryList, RenderComponentType, Renderer, SecurityContext, SimpleChange, TRANSLATIONS_FORMAT as TRANSLATIONS_FORMAT_, TemplateRef, ViewContainerRef, ViewEncapsulation} from '@angular/core';
|
||||
import {AnimationGroupPlayer as AnimationGroupPlayer_, AnimationKeyframe as AnimationKeyframe_, AnimationSequencePlayer as AnimationSequencePlayer_, AnimationStyles as AnimationStyles_, AppElement, AppView, ChangeDetectorStatus, CodegenComponentFactoryResolver, DebugAppView, DebugContext, EMPTY_ARRAY, EMPTY_MAP, NgModuleInjector, NoOpAnimationPlayer as NoOpAnimationPlayer_, StaticNodeDebugInfo, TemplateRef_, UNINITIALIZED, ValueUnwrapper, ViewType, ViewUtils, balanceAnimationKeyframes as impBalanceAnimationKeyframes, castByValue, checkBinding, clearStyles as impClearStyles, collectAndResolveStyles as impCollectAndResolveStyles, devModeEqual, flattenNestedViewRenderNodes, interpolate, prepareFinalAnimationStyles as impBalanceAnimationStyles, pureProxy1, pureProxy10, pureProxy2, pureProxy3, pureProxy4, pureProxy5, pureProxy6, pureProxy7, pureProxy8, pureProxy9, renderStyles as impRenderStyles} from '../core_private';
|
||||
|
||||
import {CompileIdentifierMetadata, CompileTokenMetadata} from './compile_metadata';
|
||||
|
@ -252,6 +251,13 @@ export class Identifiers {
|
|||
moduleUrl: ANIMATION_STYLE_UTIL_ASSET_URL,
|
||||
runtime: impCollectAndResolveStyles
|
||||
});
|
||||
static LOCALE_ID = new CompileIdentifierMetadata(
|
||||
{name: 'LOCALE_ID', moduleUrl: assetUrl('core', 'i18n/tokens'), runtime: LOCALE_ID_});
|
||||
static TRANSLATIONS_FORMAT = new CompileIdentifierMetadata({
|
||||
name: 'TRANSLATIONS_FORMAT',
|
||||
moduleUrl: assetUrl('core', 'i18n/tokens'),
|
||||
runtime: TRANSLATIONS_FORMAT_
|
||||
});
|
||||
}
|
||||
|
||||
export function identifierToken(identifier: CompileIdentifierMetadata): CompileTokenMetadata {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import {BaseException, SchemaMetadata} from '@angular/core';
|
||||
|
||||
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompilePipeMetadata, StaticSymbol, createHostComponentMeta} from './compile_metadata';
|
||||
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompilePipeMetadata, CompileProviderMetadata, CompileTokenMetadata, StaticSymbol, createHostComponentMeta} from './compile_metadata';
|
||||
import {DirectiveNormalizer} from './directive_normalizer';
|
||||
import {ListWrapper} from './facade/collection';
|
||||
import {Identifiers} from './identifiers';
|
||||
|
@ -33,7 +33,8 @@ export class OfflineCompiler {
|
|||
private _metadataResolver: CompileMetadataResolver,
|
||||
private _directiveNormalizer: DirectiveNormalizer, private _templateParser: TemplateParser,
|
||||
private _styleCompiler: StyleCompiler, private _viewCompiler: ViewCompiler,
|
||||
private _ngModuleCompiler: NgModuleCompiler, private _outputEmitter: OutputEmitter) {}
|
||||
private _ngModuleCompiler: NgModuleCompiler, private _outputEmitter: OutputEmitter,
|
||||
private _localeId: string, private _translationFormat: string) {}
|
||||
|
||||
analyzeModules(ngModules: StaticSymbol[]): NgModulesSummary {
|
||||
const ngModuleByComponent = new Map<StaticSymbol, CompileNgModuleMetadata>();
|
||||
|
@ -107,7 +108,16 @@ export class OfflineCompiler {
|
|||
|
||||
private _compileModule(ngModuleType: StaticSymbol, targetStatements: o.Statement[]): string {
|
||||
const ngModule = this._metadataResolver.getNgModuleMetadata(<any>ngModuleType);
|
||||
let appCompileResult = this._ngModuleCompiler.compile(ngModule, []);
|
||||
let appCompileResult = this._ngModuleCompiler.compile(ngModule, [
|
||||
new CompileProviderMetadata({
|
||||
token: new CompileTokenMetadata({identifier: Identifiers.LOCALE_ID}),
|
||||
useValue: this._localeId
|
||||
}),
|
||||
new CompileProviderMetadata({
|
||||
token: new CompileTokenMetadata({identifier: Identifiers.TRANSLATIONS_FORMAT}),
|
||||
useValue: this._translationFormat
|
||||
})
|
||||
]);
|
||||
appCompileResult.dependencies.forEach((dep) => {
|
||||
dep.placeholder.name = _componentFactoryName(dep.comp);
|
||||
dep.placeholder.moduleUrl = _ngfactoryModuleUrl(dep.comp.moduleUrl);
|
||||
|
|
|
@ -8,8 +8,9 @@
|
|||
|
||||
import {DirectiveResolver, XHR, i18n} from '@angular/compiler';
|
||||
import {MockDirectiveResolver} from '@angular/compiler/testing';
|
||||
import {Compiler, Component, DebugElement, Injector} from '@angular/core';
|
||||
import {Compiler, Component, DebugElement, Injector, TRANSLATIONS} from '@angular/core';
|
||||
import {TestBed, TestComponentBuilder, fakeAsync} from '@angular/core/testing';
|
||||
|
||||
import {beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit,} from '@angular/core/testing/testing_internal';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
import {By} from '@angular/platform-browser/src/dom/debug/by';
|
||||
|
@ -30,7 +31,7 @@ export function main() {
|
|||
providers: [
|
||||
{provide: XHR, useClass: SpyXHR},
|
||||
{provide: NgLocalization, useClass: FrLocalization},
|
||||
{provide: i18n.TRANSLATIONS, useValue: XTB},
|
||||
{provide: TRANSLATIONS, useValue: XTB},
|
||||
]
|
||||
});
|
||||
});
|
||||
|
@ -213,4 +214,4 @@ const XMB = `
|
|||
<ph name="START_TAG_DIV_1"><ex><div></ex></ph><ph name="ICU"/><ph name="CLOSE_TAG_DIV"><ex></div></ex></ph>
|
||||
</msg>
|
||||
<msg id="93a30c67d4e6c9b37aecfe2ac0f2b5d366d7b520">it <ph name="START_BOLD_TEXT"><ex><b></ex></ph>should<ph name="CLOSE_BOLD_TEXT"><ex></b></ex></ph> work</msg>
|
||||
</messagebundle>`;
|
||||
</messagebundle>`;
|
||||
|
|
|
@ -25,6 +25,7 @@ export * from './src/testability/testability';
|
|||
export * from './src/change_detection';
|
||||
export * from './src/platform_directives_and_pipes';
|
||||
export * from './src/platform_core_providers';
|
||||
export {TRANSLATIONS, TRANSLATIONS_FORMAT, LOCALE_ID} from './src/i18n/tokens';
|
||||
export {APPLICATION_COMMON_PROVIDERS, ApplicationModule} from './src/application_module';
|
||||
export {wtfCreateScope, wtfLeave, wtfStartTimeRange, wtfEndTimeRange, WtfScopeFn} from './src/profile/profile';
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* @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 {OpaqueToken} from '../di/opaque_token';
|
||||
|
||||
/**
|
||||
* @experimental i18n support is experimental.
|
||||
*/
|
||||
export const LOCALE_ID = new OpaqueToken('LocaleId');
|
||||
|
||||
/**
|
||||
* @experimental i18n support is experimental.
|
||||
*/
|
||||
export const TRANSLATIONS = new OpaqueToken('Translations');
|
||||
|
||||
/**
|
||||
* @experimental i18n support is experimental.
|
||||
*/
|
||||
export const TRANSLATIONS_FORMAT = new OpaqueToken('TranslationsFormat');
|
|
@ -33,7 +33,7 @@ cp -v package.json $TMP
|
|||
|
||||
./node_modules/.bin/tsc --version
|
||||
# Compile the compiler-cli integration tests
|
||||
./node_modules/.bin/ngc
|
||||
./node_modules/.bin/ngc --i18nFile=src/messages.fi.xtb --locale=fi --i18nFormat=xtb
|
||||
./node_modules/.bin/ng-xi18n
|
||||
|
||||
./node_modules/.bin/jasmine init
|
||||
|
|
|
@ -2,5 +2,6 @@ export {MetadataWriterHost, TsickleHost} from './src/compiler_host';
|
|||
export {CodegenExtension, main} from './src/main';
|
||||
|
||||
export {default as AngularCompilerOptions} from './src/options';
|
||||
export * from './src/cli_options';
|
||||
export * from './src/collector';
|
||||
export * from './src/schema';
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* @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
|
||||
*/
|
||||
export class CliOptions {
|
||||
public basePath: string;
|
||||
constructor({basePath = null}: {basePath?: string}) { this.basePath = basePath; }
|
||||
}
|
||||
|
||||
export class I18nExtractionCliOptions extends CliOptions {
|
||||
public i18nFormat: string;
|
||||
|
||||
constructor({i18nFormat = null}: {i18nFormat?: string}) {
|
||||
super({});
|
||||
this.i18nFormat = i18nFormat;
|
||||
}
|
||||
}
|
||||
|
||||
export class NgcCliOptions extends CliOptions {
|
||||
public i18nFormat: string;
|
||||
public i18nFile: string;
|
||||
public locale: string;
|
||||
|
||||
constructor({i18nFormat = null, i18nFile = null, locale = null, basePath = null}:
|
||||
{i18nFormat?: string, i18nFile?: string, locale?: string, basePath?: string}) {
|
||||
super({basePath: basePath});
|
||||
this.i18nFormat = i18nFormat;
|
||||
this.i18nFile = i18nFile;
|
||||
this.locale = locale;
|
||||
}
|
||||
}
|
|
@ -6,11 +6,14 @@ import {check, tsc} from './tsc';
|
|||
|
||||
import NgOptions from './options';
|
||||
import {MetadataWriterHost, TsickleHost} from './compiler_host';
|
||||
import {CliOptions} from './cli_options';
|
||||
|
||||
export type CodegenExtension = (ngOptions: NgOptions, program: ts.Program, host: ts.CompilerHost) =>
|
||||
Promise<void>;
|
||||
export type CodegenExtension =
|
||||
(ngOptions: NgOptions, cliOptions: CliOptions, program: ts.Program, host: ts.CompilerHost) =>
|
||||
Promise<void>;
|
||||
|
||||
export function main(project: string, basePath?: string, codegen?: CodegenExtension): Promise<any> {
|
||||
export function main(
|
||||
project: string, cliOptions: CliOptions, codegen?: CodegenExtension): Promise<any> {
|
||||
try {
|
||||
let projectDir = project;
|
||||
if (fs.lstatSync(project).isFile()) {
|
||||
|
@ -18,7 +21,7 @@ export function main(project: string, basePath?: string, codegen?: CodegenExtens
|
|||
}
|
||||
|
||||
// file names in tsconfig are resolved relative to this absolute path
|
||||
basePath = path.resolve(process.cwd(), basePath || projectDir);
|
||||
const basePath = path.resolve(process.cwd(), cliOptions.basePath || projectDir);
|
||||
|
||||
// read the configuration options from wherever you store them
|
||||
const {parsed, ngOptions} = tsc.readConfiguration(project, basePath);
|
||||
|
@ -32,7 +35,7 @@ export function main(project: string, basePath?: string, codegen?: CodegenExtens
|
|||
if (ngOptions.skipTemplateCodegen || !codegen) {
|
||||
codegen = () => Promise.resolve(null);
|
||||
}
|
||||
return codegen(ngOptions, program, host).then(() => {
|
||||
return codegen(ngOptions, cliOptions, program, host).then(() => {
|
||||
// Create a new program since codegen files were created after making the old program
|
||||
const newProgram = ts.createProgram(parsed.fileNames, parsed.options, host, program);
|
||||
tsc.typeCheck(host, newProgram);
|
||||
|
@ -59,11 +62,11 @@ export function main(project: string, basePath?: string, codegen?: CodegenExtens
|
|||
// CLI entry point
|
||||
if (require.main === module) {
|
||||
const args = require('minimist')(process.argv.slice(2));
|
||||
main(args.p || args.project || '.', args.basePath)
|
||||
.then(exitCode => process.exit(exitCode))
|
||||
.catch(e => {
|
||||
console.error(e.stack);
|
||||
console.error('Compilation failed');
|
||||
process.exit(1);
|
||||
});
|
||||
const project = args.p || args.project || '.';
|
||||
const cliOptions = new CliOptions(args);
|
||||
main(project, cliOptions).then((exitCode: any) => process.exit(exitCode)).catch((e: any) => {
|
||||
console.error(e.stack);
|
||||
console.error('Compilation failed');
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -780,6 +780,9 @@ export declare class KeyValueDiffers {
|
|||
static extend(factories: KeyValueDifferFactory[]): Provider;
|
||||
}
|
||||
|
||||
/** @experimental */
|
||||
export declare const LOCALE_ID: OpaqueToken;
|
||||
|
||||
/** @deprecated */
|
||||
export declare function lockRunMode(): void;
|
||||
|
||||
|
@ -1330,6 +1333,12 @@ export interface TrackByFn {
|
|||
/** @experimental */
|
||||
export declare function transition(stateChangeExpr: string, steps: AnimationMetadata | AnimationMetadata[]): AnimationStateTransitionMetadata;
|
||||
|
||||
/** @experimental */
|
||||
export declare const TRANSLATIONS: OpaqueToken;
|
||||
|
||||
/** @experimental */
|
||||
export declare const TRANSLATIONS_FORMAT: OpaqueToken;
|
||||
|
||||
/** @experimental */
|
||||
export declare function trigger(name: string, animation: AnimationMetadata[]): AnimationEntryMetadata;
|
||||
|
||||
|
|
Loading…
Reference in New Issue