feat(compiler): add target locale to the translation bundles (#14290)
PR Close #14290
This commit is contained in:

committed by
Miško Hevery

parent
4676df5833
commit
bb4db2d8f3
@ -63,7 +63,7 @@ const WRITE_XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
const LOAD_XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<file source-language="en" datatype="plaintext" original="ng2.template">
|
||||
<file source-language="en" target-language="fr" datatype="plaintext" original="ng2.template">
|
||||
<body>
|
||||
<trans-unit id="983775b9a51ce14b036be72d4cfd65d68d64e231" datatype="html">
|
||||
<source>translatable attribute</source>
|
||||
@ -114,7 +114,7 @@ export function main(): void {
|
||||
}
|
||||
|
||||
function loadAsMap(xliff: string): {[id: string]: string} {
|
||||
const i18nNodesByMsgId = serializer.load(xliff, 'url');
|
||||
const {i18nNodesByMsgId} = serializer.load(xliff, 'url');
|
||||
|
||||
const msgMap: {[id: string]: string} = {};
|
||||
Object.keys(i18nNodesByMsgId)
|
||||
@ -143,6 +143,10 @@ export function main(): void {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the target locale',
|
||||
() => { expect(serializer.load(LOAD_XLIFF, 'url').locale).toEqual('fr'); });
|
||||
|
||||
|
||||
describe('structure errors', () => {
|
||||
it('should throw when a trans-unit has no translation', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
@ -18,7 +18,7 @@ export function main(): void {
|
||||
const serializer = new Xtb();
|
||||
|
||||
function loadAsMap(xtb: string): {[id: string]: string} {
|
||||
const i18nNodesByMsgId = serializer.load(xtb, 'url');
|
||||
const {i18nNodesByMsgId} = serializer.load(xtb, 'url');
|
||||
const msgMap: {[id: string]: string} = {};
|
||||
Object.keys(i18nNodesByMsgId).forEach(id => {
|
||||
msgMap[id] = serializeNodes(i18nNodesByMsgId[id]).join('');
|
||||
@ -54,6 +54,14 @@ export function main(): void {
|
||||
expect(loadAsMap(XTB)).toEqual({'8841459487341224498': 'rab'});
|
||||
});
|
||||
|
||||
it('should return the target locale', () => {
|
||||
const XTB = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<translationbundle lang='fr'>
|
||||
<translation id="8841459487341224498">rab</translation>
|
||||
</translationbundle>`;
|
||||
|
||||
expect(serializer.load(XTB, 'url').locale).toEqual('fr');
|
||||
});
|
||||
|
||||
it('should load XTB files with placeholders', () => {
|
||||
const XTB = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
@ -111,7 +119,9 @@ export function main(): void {
|
||||
|
||||
// Invalid messages should not cause the parser to throw
|
||||
let i18nNodesByMsgId: {[id: string]: i18n.Node[]};
|
||||
expect(() => { i18nNodesByMsgId = serializer.load(XTB, 'url'); }).not.toThrow();
|
||||
expect(() => {
|
||||
i18nNodesByMsgId = serializer.load(XTB, 'url').i18nNodesByMsgId;
|
||||
}).not.toThrow();
|
||||
|
||||
expect(Object.keys(i18nNodesByMsgId).length).toEqual(2);
|
||||
expect(serializeNodes(i18nNodesByMsgId['angular']).join('')).toEqual('is great');
|
||||
|
Reference in New Issue
Block a user