feat(i18n): xliff integration
This commit is contained in:

committed by
Vikram Subramanian

parent
96bf42261b
commit
f6a7d6504c
@ -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_INITIALIZER, PlatformRef, Provider, ReflectiveInjector, TRANSLATIONS, Type, ViewEncapsulation, createPlatformFactory, isDevMode, platformCore} from '@angular/core';
|
||||
import {COMPILER_OPTIONS, Compiler, CompilerFactory, CompilerOptions, Component, Inject, Injectable, OptionalMetadata, PLATFORM_INITIALIZER, PlatformRef, Provider, ReflectiveInjector, TRANSLATIONS, TRANSLATIONS_FORMAT, Type, ViewEncapsulation, createPlatformFactory, isDevMode, platformCore} from '@angular/core';
|
||||
|
||||
export * from './template_parser/template_ast';
|
||||
export {TEMPLATE_TRANSFORMS} from './template_parser/template_parser';
|
||||
@ -63,9 +63,13 @@ export const COMPILER_PROVIDERS: Array<any|Type<any>|{[k: string]: any}|any[]> =
|
||||
HtmlParser,
|
||||
{
|
||||
provide: i18n.HtmlParser,
|
||||
useFactory: (parser: HtmlParser, translations: string) =>
|
||||
new i18n.HtmlParser(parser, translations),
|
||||
deps: [HtmlParser, [new OptionalMetadata(), new Inject(TRANSLATIONS)]]
|
||||
useFactory: (parser: HtmlParser, translations: string, format: string) =>
|
||||
new i18n.HtmlParser(parser, translations, format),
|
||||
deps: [
|
||||
HtmlParser,
|
||||
[new OptionalMetadata(), new Inject(TRANSLATIONS)],
|
||||
[new OptionalMetadata(), new Inject(TRANSLATIONS_FORMAT)],
|
||||
]
|
||||
},
|
||||
TemplateParser,
|
||||
DirectiveNormalizer,
|
||||
|
@ -12,17 +12,22 @@ import {ParseTreeResult} from '../ml_parser/parser';
|
||||
|
||||
import {mergeTranslations} from './extractor_merger';
|
||||
import {MessageBundle} from './message_bundle';
|
||||
import {Serializer} from './serializers/serializer';
|
||||
import {Xliff} from './serializers/xliff';
|
||||
import {Xmb} from './serializers/xmb';
|
||||
import {Xtb} from './serializers/xtb';
|
||||
import {TranslationBundle} from './translation_bundle';
|
||||
|
||||
export class HtmlParser implements BaseHtmlParser {
|
||||
// @override
|
||||
public getTagDefinition: any;
|
||||
getTagDefinition: any;
|
||||
|
||||
// TODO(vicb): transB.load() should not need a msgB & add transB.resolve(msgB,
|
||||
// interpolationConfig)
|
||||
// TODO(vicb): remove the interpolationConfig from the Xtb serializer
|
||||
constructor(private _htmlParser: BaseHtmlParser, private _translations?: string) {}
|
||||
constructor(
|
||||
private _htmlParser: BaseHtmlParser, private _translations?: string,
|
||||
private _translationsFormat?: string) {}
|
||||
|
||||
parse(
|
||||
source: string, url: string, parseExpansionForms: boolean = false,
|
||||
@ -43,9 +48,25 @@ export class HtmlParser implements BaseHtmlParser {
|
||||
return new ParseTreeResult(parseResult.rootNodes, parseResult.errors.concat(errors));
|
||||
}
|
||||
|
||||
const xtb = new Xtb(this._htmlParser, interpolationConfig);
|
||||
const translationBundle = TranslationBundle.load(this._translations, url, messageBundle, xtb);
|
||||
const serializer = this._createSerializer(interpolationConfig);
|
||||
const translationBundle =
|
||||
TranslationBundle.load(this._translations, url, messageBundle, serializer);
|
||||
|
||||
return mergeTranslations(parseResult.rootNodes, translationBundle, interpolationConfig, [], {});
|
||||
}
|
||||
|
||||
private _createSerializer(interpolationConfig: InterpolationConfig): Serializer {
|
||||
const format = (this._translationsFormat || 'xlf').toLowerCase();
|
||||
|
||||
switch (format) {
|
||||
case 'xmb':
|
||||
return new Xmb();
|
||||
case 'xtb':
|
||||
return new Xtb(this._htmlParser, interpolationConfig);
|
||||
case 'xliff':
|
||||
case 'xlf':
|
||||
default:
|
||||
return new Xliff(this._htmlParser, interpolationConfig);
|
||||
}
|
||||
}
|
||||
}
|
@ -9,5 +9,6 @@
|
||||
export {HtmlParser} from './html_parser';
|
||||
export {MessageBundle} from './message_bundle';
|
||||
export {Serializer} from './serializers/serializer';
|
||||
export {Xliff} from './serializers/xliff';
|
||||
export {Xmb} from './serializers/xmb';
|
||||
export {Xtb} from './serializers/xtb';
|
||||
|
Reference in New Issue
Block a user