feat(compiler): Implement i18n XLIFF 2.0 serializer (#14185)

- Ensure that the result passes OASIS XLIFF 2.0 schema validation
- Use <ph/> for self-closing placeholder tags
- Use <pc></pc> for other placeholder tags
- Check for the correct XLIFF file version
- Add ICU support

fixes #11735
This commit is contained in:
Panuruj Khambanonda (PK)
2017-04-14 09:05:00 -07:00
committed by Tobias Bosch
parent 8ad464d90e
commit 09c4cb2540
7 changed files with 761 additions and 6 deletions

View File

@ -34,7 +34,7 @@ export class Extractor {
const promiseBundle = this.extractBundle();
return promiseBundle.then(bundle => {
const content = this.serialize(bundle, ext);
const content = this.serialize(bundle, formatName);
const dstFile = outFile || `messages.${ext}`;
const dstPath = path.join(this.options.genDir, dstFile);
this.host.writeFile(dstPath, content, false);
@ -48,14 +48,20 @@ export class Extractor {
return this.ngExtractor.extract(files);
}
serialize(bundle: compiler.MessageBundle, ext: string): string {
serialize(bundle: compiler.MessageBundle, formatName: string): string {
const format = formatName.toLowerCase();
let serializer: compiler.Serializer;
switch (ext) {
switch (format) {
case 'xmb':
serializer = new compiler.Xmb();
break;
case 'xliff2':
case 'xlf2':
serializer = new compiler.Xliff2();
break;
case 'xlf':
case 'xliff':
default:
serializer = new compiler.Xliff();
}
@ -66,10 +72,18 @@ export class Extractor {
getExtension(formatName: string): string {
const format = (formatName || 'xlf').toLowerCase();
if (format === 'xmb') return 'xmb';
if (format === 'xlf' || format === 'xlif' || format === 'xliff') return 'xlf';
switch (format) {
case 'xmb':
return 'xmb';
case 'xlf':
case 'xlif':
case 'xliff':
case 'xlf2':
case 'xliff2':
return 'xlf';
}
throw new Error('Unsupported format "${formatName}"');
throw new Error(`Unsupported format "${formatName}"`);
}
static create(