feat(compiler-cli): add a locale
option to ng-xi18n
Fixes #12303 Closes #14537
This commit is contained in:
@ -107,8 +107,8 @@ const LOAD_XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
export function main(): void {
|
||||
const serializer = new Xliff();
|
||||
|
||||
function toXliff(html: string): string {
|
||||
const catalog = new MessageBundle(new HtmlParser, [], {});
|
||||
function toXliff(html: string, locale: string | null = null): string {
|
||||
const catalog = new MessageBundle(new HtmlParser, [], {}, locale);
|
||||
catalog.updateFromTemplate(html, '', DEFAULT_INTERPOLATION_CONFIG);
|
||||
return catalog.write(serializer);
|
||||
}
|
||||
@ -126,6 +126,8 @@ export function main(): void {
|
||||
describe('XLIFF serializer', () => {
|
||||
describe('write', () => {
|
||||
it('should write a valid xliff file', () => { expect(toXliff(HTML)).toEqual(WRITE_XLIFF); });
|
||||
it('should write a valid xliff file with a source language',
|
||||
() => { expect(toXliff(HTML, 'fr')).toContain('file source-language="fr"'); });
|
||||
});
|
||||
|
||||
describe('load', () => {
|
||||
@ -247,4 +249,4 @@ export function main(): void {
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,11 @@ export function main(): void {
|
||||
</messagebundle>
|
||||
`;
|
||||
|
||||
it('should write a valid xmb file', () => { expect(toXmb(HTML)).toEqual(XMB); });
|
||||
it('should write a valid xmb file', () => {
|
||||
expect(toXmb(HTML)).toEqual(XMB);
|
||||
// the locale is not specified in the xmb file
|
||||
expect(toXmb(HTML, 'fr')).toEqual(XMB);
|
||||
});
|
||||
|
||||
it('should throw when trying to load an xmb file', () => {
|
||||
expect(() => {
|
||||
@ -67,8 +71,8 @@ export function main(): void {
|
||||
});
|
||||
}
|
||||
|
||||
function toXmb(html: string): string {
|
||||
const catalog = new MessageBundle(new HtmlParser, [], {});
|
||||
function toXmb(html: string, locale: string | null = null): string {
|
||||
const catalog = new MessageBundle(new HtmlParser, [], {}, locale);
|
||||
const serializer = new Xmb();
|
||||
|
||||
catalog.updateFromTemplate(html, '', DEFAULT_INTERPOLATION_CONFIG);
|
||||
|
@ -186,8 +186,8 @@ export function main(): void {
|
||||
});
|
||||
|
||||
it('should throw when trying to save an xtb file',
|
||||
() => { expect(() => { serializer.write([]); }).toThrowError(/Unsupported/); });
|
||||
() => { expect(() => { serializer.write([], null); }).toThrowError(/Unsupported/); });
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user