style(compiler): reformat of codebase with new clang-format version (#36520)
This commit reformats the packages/compiler tree using the new version of clang-format. PR Close #36520
This commit is contained in:
@ -27,14 +27,17 @@ import {computeMsgId, digest, sha1} from '../../src/i18n/digest';
|
||||
});
|
||||
|
||||
describe('sha1', () => {
|
||||
it('should work on empty strings',
|
||||
() => { expect(sha1('')).toEqual('da39a3ee5e6b4b0d3255bfef95601890afd80709'); });
|
||||
it('should work on empty strings', () => {
|
||||
expect(sha1('')).toEqual('da39a3ee5e6b4b0d3255bfef95601890afd80709');
|
||||
});
|
||||
|
||||
it('should returns the sha1 of "hello world"',
|
||||
() => { expect(sha1('abc')).toEqual('a9993e364706816aba3e25717850c26c9cd0d89d'); });
|
||||
it('should returns the sha1 of "hello world"', () => {
|
||||
expect(sha1('abc')).toEqual('a9993e364706816aba3e25717850c26c9cd0d89d');
|
||||
});
|
||||
|
||||
it('should returns the sha1 of unicode strings',
|
||||
() => { expect(sha1('你好,世界')).toEqual('3becb03b015ed48050611c8d7afe4b88f70d5a20'); });
|
||||
it('should returns the sha1 of unicode strings', () => {
|
||||
expect(sha1('你好,世界')).toEqual('3becb03b015ed48050611c8d7afe4b88f70d5a20');
|
||||
});
|
||||
|
||||
it('should support arbitrary string size', () => {
|
||||
// node.js reference code:
|
||||
@ -89,8 +92,9 @@ import {computeMsgId, digest, sha1} from '../../src/i18n/digest';
|
||||
'': '4416290763660062288',
|
||||
};
|
||||
|
||||
Object.keys(fixtures).forEach(
|
||||
msg => { expect(computeMsgId(msg, '')).toEqual(fixtures[msg]); });
|
||||
Object.keys(fixtures).forEach(msg => {
|
||||
expect(computeMsgId(msg, '')).toEqual(fixtures[msg]);
|
||||
});
|
||||
});
|
||||
|
||||
it('should work on well known inputs with meaning', () => {
|
||||
@ -100,8 +104,9 @@ import {computeMsgId, digest, sha1} from '../../src/i18n/digest';
|
||||
'3993998469942805487': ['View', 'Gmail UI'],
|
||||
};
|
||||
|
||||
Object.keys(fixtures).forEach(
|
||||
id => { expect(computeMsgId(fixtures[id][0], fixtures[id][1])).toEqual(id); });
|
||||
Object.keys(fixtures).forEach(id => {
|
||||
expect(computeMsgId(fixtures[id][0], fixtures[id][1])).toEqual(id);
|
||||
});
|
||||
});
|
||||
|
||||
it('should support arbitrary string size', () => {
|
||||
@ -116,7 +121,6 @@ import {computeMsgId, digest, sha1} from '../../src/i18n/digest';
|
||||
}
|
||||
expect(computeMsgId(result, '')).toEqual('2122606631351252558');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -94,8 +94,9 @@ import {serializeNodes as serializeHtmlNodes} from '../ml_parser/util/util';
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not create a message for empty elements',
|
||||
() => { expect(extract('<div i18n="m|d"></div>')).toEqual([]); });
|
||||
it('should not create a message for empty elements', () => {
|
||||
expect(extract('<div i18n="m|d"></div>')).toEqual([]);
|
||||
});
|
||||
|
||||
it('should ignore implicit elements in translatable elements', () => {
|
||||
expect(extract('<div i18n="m|d"><p></p></div>', ['p'])).toEqual([
|
||||
@ -138,7 +139,8 @@ import {serializeNodes as serializeHtmlNodes} from '../ml_parser/util/util';
|
||||
],
|
||||
[
|
||||
[
|
||||
'text', '<ph tag name="START_PARAGRAPH">html, <ph tag' +
|
||||
'text',
|
||||
'<ph tag name="START_PARAGRAPH">html, <ph tag' +
|
||||
' name="START_BOLD_TEXT">nested</ph name="CLOSE_BOLD_TEXT"></ph name="CLOSE_PARAGRAPH">',
|
||||
'<ph icu name="ICU">{count, plural, =0 {[<ph tag' +
|
||||
' name="START_TAG_SPAN">html</ph name="CLOSE_TAG_SPAN">]}}</ph>',
|
||||
@ -156,8 +158,9 @@ import {serializeNodes as serializeHtmlNodes} from '../ml_parser/util/util';
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not create a message for empty blocks',
|
||||
() => { expect(extract(`<!-- i18n: meaning1|desc1 --><!-- /i18n -->`)).toEqual([]); });
|
||||
it('should not create a message for empty blocks', () => {
|
||||
expect(extract(`<!-- i18n: meaning1|desc1 --><!-- /i18n -->`)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ICU messages', () => {
|
||||
@ -199,8 +202,9 @@ import {serializeNodes as serializeHtmlNodes} from '../ml_parser/util/util';
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not extract ICU messages outside of i18n sections',
|
||||
() => { expect(extract('{count, plural, =0 {text}}')).toEqual([]); });
|
||||
it('should not extract ICU messages outside of i18n sections', () => {
|
||||
expect(extract('{count, plural, =0 {text}}')).toEqual([]);
|
||||
});
|
||||
|
||||
it('should ignore nested ICU messages', () => {
|
||||
expect(extract('<div i18n="m|d">{count, plural, =0 { {sex, select, male {m}} }}</div>'))
|
||||
@ -280,8 +284,9 @@ import {serializeNodes as serializeHtmlNodes} from '../ml_parser/util/util';
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not create a message for empty attributes',
|
||||
() => { expect(extract('<div i18n-title="m|d" title></div>')).toEqual([]); });
|
||||
it('should not create a message for empty attributes', () => {
|
||||
expect(extract('<div i18n-title="m|d" title></div>')).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('implicit elements', () => {
|
||||
@ -292,7 +297,7 @@ import {serializeNodes as serializeHtmlNodes} from '../ml_parser/util/util';
|
||||
});
|
||||
|
||||
it('should allow nested implicit elements', () => {
|
||||
let result: any[] = undefined !;
|
||||
let result: any[] = undefined!;
|
||||
|
||||
expect(() => {
|
||||
result = extract('<div>outer<div>inner</div></div>', ['div']);
|
||||
@ -302,7 +307,6 @@ import {serializeNodes as serializeHtmlNodes} from '../ml_parser/util/util';
|
||||
[['outer', '<ph tag name="START_TAG_DIV">inner</ph name="CLOSE_TAG_DIV">'], '', '', ''],
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('implicit attributes', () => {
|
||||
@ -341,7 +345,6 @@ import {serializeNodes as serializeHtmlNodes} from '../ml_parser/util/util';
|
||||
['Could not start a block inside a translatable section', '<!--'],
|
||||
['Trying to close an unopened block', '<!--'],
|
||||
]);
|
||||
|
||||
});
|
||||
|
||||
it('should report unclosed blocks', () => {
|
||||
@ -527,7 +530,7 @@ function fakeTranslate(
|
||||
messages.forEach(message => {
|
||||
const id = digest(message);
|
||||
const text = serializeI18nNodes(message.nodes).join('').replace(/</g, '[');
|
||||
i18nMsgMap[id] = [new i18n.Text(`**${text}**`, null !)];
|
||||
i18nMsgMap[id] = [new i18n.Text(`**${text}**`, null!)];
|
||||
});
|
||||
|
||||
const translationBundle = new TranslationBundle(i18nMsgMap, null, digest);
|
||||
|
@ -26,6 +26,5 @@ import {ParseTreeResult} from '@angular/compiler/src/ml_parser/parser';
|
||||
i18nHtmlParser.parse('source', 'url');
|
||||
expect(TranslationBundle.load).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import {DEFAULT_INTERPOLATION_CONFIG} from '@angular/compiler/src/ml_parser/inte
|
||||
|
||||
{
|
||||
describe('I18nParser', () => {
|
||||
|
||||
describe('elements', () => {
|
||||
it('should extract from elements', () => {
|
||||
expect(_humanizeMessages('<div i18n="m|d">text</div>')).toEqual([
|
||||
@ -34,11 +33,13 @@ import {DEFAULT_INTERPOLATION_CONFIG} from '@angular/compiler/src/ml_parser/inte
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not create a message for empty elements',
|
||||
() => { expect(_humanizeMessages('<div i18n="m|d"></div>')).toEqual([]); });
|
||||
it('should not create a message for empty elements', () => {
|
||||
expect(_humanizeMessages('<div i18n="m|d"></div>')).toEqual([]);
|
||||
});
|
||||
|
||||
it('should not create a message for plain elements',
|
||||
() => { expect(_humanizeMessages('<div></div>')).toEqual([]); });
|
||||
it('should not create a message for plain elements', () => {
|
||||
expect(_humanizeMessages('<div></div>')).toEqual([]);
|
||||
});
|
||||
|
||||
it('should support void elements', () => {
|
||||
expect(_humanizeMessages('<div i18n="m|d"><p><br></p></div>')).toEqual([
|
||||
@ -115,8 +116,9 @@ import {DEFAULT_INTERPOLATION_CONFIG} from '@angular/compiler/src/ml_parser/inte
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not create a message for empty attributes',
|
||||
() => { expect(_humanizeMessages('<div i18n-title="m|d" title></div>')).toEqual([]); });
|
||||
it('should not create a message for empty attributes', () => {
|
||||
expect(_humanizeMessages('<div i18n-title="m|d" title></div>')).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('interpolation', () => {
|
||||
@ -252,7 +254,6 @@ import {DEFAULT_INTERPOLATION_CONFIG} from '@angular/compiler/src/ml_parser/inte
|
||||
expect(_humanizePlaceholders(html)).toEqual([
|
||||
'START_PARAGRAPH=<p>, CLOSE_PARAGRAPH=</p>, START_PARAGRAPH_1=<p other>',
|
||||
]);
|
||||
|
||||
});
|
||||
|
||||
it('should reuse the same placeholder name for interpolations', () => {
|
||||
@ -302,7 +303,6 @@ import {DEFAULT_INTERPOLATION_CONFIG} from '@angular/compiler/src/ml_parser/inte
|
||||
'',
|
||||
'',
|
||||
]);
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -20,11 +20,11 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
})
|
||||
export class I18nComponent {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
count !: number;
|
||||
count!: number;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
sex !: string;
|
||||
sex!: string;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
sexB !: string;
|
||||
sexB!: string;
|
||||
response: any = {getItemsList: (): any[] => []};
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import {Xliff2} from '@angular/compiler/src/i18n/serializers/xliff2';
|
||||
import {HtmlParser} from '@angular/compiler/src/ml_parser/html_parser';
|
||||
import {DEFAULT_INTERPOLATION_CONFIG} from '@angular/compiler/src/ml_parser/interpolation_config';
|
||||
import {DebugElement, TRANSLATIONS, TRANSLATIONS_FORMAT} from '@angular/core';
|
||||
import {ComponentFixture, TestBed, async} from '@angular/core/testing';
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
|
||||
import {SpyResourceLoader} from '../spies';
|
||||
@ -22,7 +22,6 @@ import {FrLocalization, HTML, I18nComponent, validateHtml} from './integration_c
|
||||
|
||||
{
|
||||
describe('i18n XLIFF 2.0 integration spec', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureCompiler({
|
||||
providers: [
|
||||
|
@ -13,7 +13,7 @@ import {Xliff} from '@angular/compiler/src/i18n/serializers/xliff';
|
||||
import {HtmlParser} from '@angular/compiler/src/ml_parser/html_parser';
|
||||
import {DEFAULT_INTERPOLATION_CONFIG} from '@angular/compiler/src/ml_parser/interpolation_config';
|
||||
import {DebugElement, TRANSLATIONS, TRANSLATIONS_FORMAT} from '@angular/core';
|
||||
import {ComponentFixture, TestBed, async} from '@angular/core/testing';
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
|
||||
import {SpyResourceLoader} from '../spies';
|
||||
@ -22,7 +22,6 @@ import {FrLocalization, HTML, I18nComponent, validateHtml} from './integration_c
|
||||
|
||||
{
|
||||
describe('i18n XLIFF integration spec', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureCompiler({
|
||||
providers: [
|
||||
|
@ -13,7 +13,7 @@ import {Xmb} from '@angular/compiler/src/i18n/serializers/xmb';
|
||||
import {HtmlParser} from '@angular/compiler/src/ml_parser/html_parser';
|
||||
import {DEFAULT_INTERPOLATION_CONFIG} from '@angular/compiler/src/ml_parser/interpolation_config';
|
||||
import {DebugElement, TRANSLATIONS, TRANSLATIONS_FORMAT} from '@angular/core';
|
||||
import {ComponentFixture, TestBed, async} from '@angular/core/testing';
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
|
||||
import {SpyResourceLoader} from '../spies';
|
||||
@ -22,7 +22,6 @@ import {FrLocalization, HTML, I18nComponent, validateHtml} from './integration_c
|
||||
|
||||
{
|
||||
describe('i18n XMB/XTB integration spec', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureCompiler({
|
||||
providers: [
|
||||
|
@ -18,7 +18,9 @@ import {DEFAULT_INTERPOLATION_CONFIG} from '../../src/ml_parser/interpolation_co
|
||||
describe('Messages', () => {
|
||||
let messages: MessageBundle;
|
||||
|
||||
beforeEach(() => { messages = new MessageBundle(new HtmlParser, [], {}); });
|
||||
beforeEach(() => {
|
||||
messages = new MessageBundle(new HtmlParser, [], {});
|
||||
});
|
||||
|
||||
it('should extract the message to the catalog', () => {
|
||||
messages.updateFromTemplate(
|
||||
@ -48,11 +50,13 @@ class _TestSerializer extends Serializer {
|
||||
}
|
||||
|
||||
load(content: string, url: string):
|
||||
{locale: string | null, i18nNodesByMsgId: {[id: string]: i18n.Node[]}} {
|
||||
{locale: string|null, i18nNodesByMsgId: {[id: string]: i18n.Node[]}} {
|
||||
return {locale: null, i18nNodesByMsgId: {}};
|
||||
}
|
||||
|
||||
digest(msg: i18n.Message): string { return msg.id || `default`; }
|
||||
digest(msg: i18n.Message): string {
|
||||
return msg.id || `default`;
|
||||
}
|
||||
}
|
||||
|
||||
function humanizeMessages(catalog: MessageBundle): string[] {
|
||||
|
@ -36,13 +36,13 @@ import {_extractMessages} from '../i18n_parser_spec';
|
||||
const visitor = new RecurseVisitor();
|
||||
const container = new i18n.Container(
|
||||
[
|
||||
new i18n.Text('', null !),
|
||||
new i18n.Placeholder('', '', null !),
|
||||
new i18n.IcuPlaceholder(null !, '', null !),
|
||||
new i18n.Text('', null!),
|
||||
new i18n.Placeholder('', '', null!),
|
||||
new i18n.IcuPlaceholder(null!, '', null!),
|
||||
],
|
||||
null !);
|
||||
const tag = new i18n.TagPlaceholder('', {}, '', '', [container], false, null !);
|
||||
const icu = new i18n.Icu('', '', {tag}, null !);
|
||||
null!);
|
||||
const tag = new i18n.TagPlaceholder('', {}, '', '', [container], false, null!);
|
||||
const icu = new i18n.Icu('', '', {tag}, null!);
|
||||
|
||||
icu.visit(visitor);
|
||||
expect(visitor.textCount).toEqual(1);
|
||||
@ -58,9 +58,15 @@ class RecurseVisitor extends i18n.RecurseVisitor {
|
||||
phCount = 0;
|
||||
icuPhCount = 0;
|
||||
|
||||
visitText(text: i18n.Text, context?: any): any { this.textCount++; }
|
||||
visitText(text: i18n.Text, context?: any): any {
|
||||
this.textCount++;
|
||||
}
|
||||
|
||||
visitPlaceholder(ph: i18n.Placeholder, context?: any): any { this.phCount++; }
|
||||
visitPlaceholder(ph: i18n.Placeholder, context?: any): any {
|
||||
this.phCount++;
|
||||
}
|
||||
|
||||
visitIcuPlaceholder(ph: i18n.IcuPlaceholder, context?: any): any { this.icuPhCount++; }
|
||||
visitIcuPlaceholder(ph: i18n.IcuPlaceholder, context?: any): any {
|
||||
this.icuPhCount++;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,9 @@ import {PlaceholderRegistry} from '../../../src/i18n/serializers/placeholder';
|
||||
describe('PlaceholderRegistry', () => {
|
||||
let reg: PlaceholderRegistry;
|
||||
|
||||
beforeEach(() => { reg = new PlaceholderRegistry(); });
|
||||
beforeEach(() => {
|
||||
reg = new PlaceholderRegistry();
|
||||
});
|
||||
|
||||
describe('tag placeholder', () => {
|
||||
it('should generate names for well known tags', () => {
|
||||
@ -84,7 +86,6 @@ import {PlaceholderRegistry} from '../../../src/i18n/serializers/placeholder';
|
||||
expect(reg.getPlaceholderName('name1', 'content')).toEqual('NAME1');
|
||||
expect(reg.getPlaceholderName('name2', 'content')).toEqual('NAME2');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
@ -261,65 +261,67 @@ lignes</target>
|
||||
`;
|
||||
|
||||
(function() {
|
||||
const serializer = new Xliff2();
|
||||
const serializer = new Xliff2();
|
||||
|
||||
function toXliff(html: string, locale: string | null = null): string {
|
||||
const catalog = new MessageBundle(new HtmlParser, [], {}, locale);
|
||||
catalog.updateFromTemplate(html, 'file.ts', DEFAULT_INTERPOLATION_CONFIG);
|
||||
return catalog.write(serializer);
|
||||
}
|
||||
function toXliff(html: string, locale: string|null = null): string {
|
||||
const catalog = new MessageBundle(new HtmlParser, [], {}, locale);
|
||||
catalog.updateFromTemplate(html, 'file.ts', DEFAULT_INTERPOLATION_CONFIG);
|
||||
return catalog.write(serializer);
|
||||
}
|
||||
|
||||
function loadAsMap(xliff: string): {[id: string]: string} {
|
||||
const {i18nNodesByMsgId} = serializer.load(xliff, 'url');
|
||||
function loadAsMap(xliff: string): {[id: string]: string} {
|
||||
const {i18nNodesByMsgId} = serializer.load(xliff, 'url');
|
||||
|
||||
const msgMap: {[id: string]: string} = {};
|
||||
Object.keys(i18nNodesByMsgId)
|
||||
.forEach(id => msgMap[id] = serializeNodes(i18nNodesByMsgId[id]).join(''));
|
||||
const msgMap: {[id: string]: string} = {};
|
||||
Object.keys(i18nNodesByMsgId)
|
||||
.forEach(id => msgMap[id] = serializeNodes(i18nNodesByMsgId[id]).join(''));
|
||||
|
||||
return msgMap;
|
||||
}
|
||||
return msgMap;
|
||||
}
|
||||
|
||||
describe('XLIFF 2.0 serializer', () => {
|
||||
describe('write', () => {
|
||||
it('should write a valid xliff 2.0 file',
|
||||
() => { expect(toXliff(HTML)).toEqual(WRITE_XLIFF); });
|
||||
it('should write a valid xliff 2.0 file with a source language',
|
||||
() => { expect(toXliff(HTML, 'fr')).toContain('srcLang="fr"'); });
|
||||
describe('XLIFF 2.0 serializer', () => {
|
||||
describe('write', () => {
|
||||
it('should write a valid xliff 2.0 file', () => {
|
||||
expect(toXliff(HTML)).toEqual(WRITE_XLIFF);
|
||||
});
|
||||
it('should write a valid xliff 2.0 file with a source language', () => {
|
||||
expect(toXliff(HTML, 'fr')).toContain('srcLang="fr"');
|
||||
});
|
||||
});
|
||||
|
||||
describe('load', () => {
|
||||
it('should load XLIFF files', () => {
|
||||
expect(loadAsMap(LOAD_XLIFF)).toEqual({
|
||||
'1933478729560469763': 'etubirtta elbatalsnart',
|
||||
'7056919470098446707':
|
||||
'<ph name="INTERPOLATION"/> <ph name="START_BOLD_TEXT"/>sredlohecalp htiw<ph name="CLOSE_BOLD_TEXT"/> tnemele elbatalsnart',
|
||||
'2981514368455622387':
|
||||
'{VAR_PLURAL, plural, =0 {[<ph name="START_PARAGRAPH"/>, TEST, <ph name="CLOSE_PARAGRAPH"/>]}}',
|
||||
'i': 'oof',
|
||||
'6440235004920703622':
|
||||
'<ph name="START_BOLD_TEXT"/><ph name="START_UNDERLINED_TEXT"/>txeT <ph name="INTERPOLATION"/><ph name="CLOSE_UNDERLINED_TEXT"/><ph name="CLOSE_BOLD_TEXT"/>',
|
||||
'8779402634269838862':
|
||||
'<ph name="TAG_IMG_1"/><ph name="TAG_IMG"/><ph name="LINE_BREAK"/>',
|
||||
'6536355551500405293': '<ph name="START_TAG_SPAN"/><ph name="CLOSE_TAG_SPAN"/> olleh',
|
||||
'baz':
|
||||
'{VAR_PLURAL, plural, =0 {[{VAR_SELECT, select, other {[<ph name="START_PARAGRAPH"/>, profondément imbriqué, <ph name="CLOSE_PARAGRAPH"/>]}}, ]}}',
|
||||
'6997386649824869937': 'Test: <ph name="ICU"/>',
|
||||
'5229984852258993423': '{VAR_PLURAL, plural, =0 {[{VAR_SELECT, select, other {[<ph' +
|
||||
' name="START_PARAGRAPH"/>, profondément imbriqué, <ph name="CLOSE_PARAGRAPH"/>]}}, ]}, =other {[beaucoup]}}',
|
||||
'2340165783990709777': `multi
|
||||
describe('load', () => {
|
||||
it('should load XLIFF files', () => {
|
||||
expect(loadAsMap(LOAD_XLIFF)).toEqual({
|
||||
'1933478729560469763': 'etubirtta elbatalsnart',
|
||||
'7056919470098446707':
|
||||
'<ph name="INTERPOLATION"/> <ph name="START_BOLD_TEXT"/>sredlohecalp htiw<ph name="CLOSE_BOLD_TEXT"/> tnemele elbatalsnart',
|
||||
'2981514368455622387':
|
||||
'{VAR_PLURAL, plural, =0 {[<ph name="START_PARAGRAPH"/>, TEST, <ph name="CLOSE_PARAGRAPH"/>]}}',
|
||||
'i': 'oof',
|
||||
'6440235004920703622':
|
||||
'<ph name="START_BOLD_TEXT"/><ph name="START_UNDERLINED_TEXT"/>txeT <ph name="INTERPOLATION"/><ph name="CLOSE_UNDERLINED_TEXT"/><ph name="CLOSE_BOLD_TEXT"/>',
|
||||
'8779402634269838862': '<ph name="TAG_IMG_1"/><ph name="TAG_IMG"/><ph name="LINE_BREAK"/>',
|
||||
'6536355551500405293': '<ph name="START_TAG_SPAN"/><ph name="CLOSE_TAG_SPAN"/> olleh',
|
||||
'baz':
|
||||
'{VAR_PLURAL, plural, =0 {[{VAR_SELECT, select, other {[<ph name="START_PARAGRAPH"/>, profondément imbriqué, <ph name="CLOSE_PARAGRAPH"/>]}}, ]}}',
|
||||
'6997386649824869937': 'Test: <ph name="ICU"/>',
|
||||
'5229984852258993423': '{VAR_PLURAL, plural, =0 {[{VAR_SELECT, select, other {[<ph' +
|
||||
' name="START_PARAGRAPH"/>, profondément imbriqué, <ph name="CLOSE_PARAGRAPH"/>]}}, ]}, =other {[beaucoup]}}',
|
||||
'2340165783990709777': `multi
|
||||
lignes`,
|
||||
'mrk-test': 'Vous pouvez utiliser votre propre namespace.',
|
||||
'mrk-test2': 'Vous pouvez utiliser votre propre namespace.'
|
||||
});
|
||||
'mrk-test': 'Vous pouvez utiliser votre propre namespace.',
|
||||
'mrk-test2': 'Vous pouvez utiliser votre propre namespace.'
|
||||
});
|
||||
|
||||
it('should return the target locale',
|
||||
() => { expect(serializer.load(LOAD_XLIFF, 'url').locale).toEqual('fr'); });
|
||||
});
|
||||
|
||||
describe('structure errors', () => {
|
||||
it('should throw when a wrong xliff version is used', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
it('should return the target locale', () => {
|
||||
expect(serializer.load(LOAD_XLIFF, 'url').locale).toEqual('fr');
|
||||
});
|
||||
});
|
||||
|
||||
describe('structure errors', () => {
|
||||
it('should throw when a wrong xliff version is used', () => {
|
||||
const 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">
|
||||
<body>
|
||||
@ -331,13 +333,13 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/The XLIFF file version 1.2 is not compatible with XLIFF 2.0 serializer/);
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/The XLIFF file version 1.2 is not compatible with XLIFF 2.0 serializer/);
|
||||
});
|
||||
|
||||
it('should throw when an unit has no translation', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
it('should throw when an unit has no translation', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en">
|
||||
<file original="ng.template" id="ngi18n">
|
||||
<unit id="missingtarget">
|
||||
@ -348,14 +350,14 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/Message missingtarget misses a translation/);
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/Message missingtarget misses a translation/);
|
||||
});
|
||||
|
||||
|
||||
it('should throw when an unit has no id attribute', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
it('should throw when an unit has no id attribute', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en">
|
||||
<file original="ng.template" id="ngi18n">
|
||||
<unit>
|
||||
@ -367,11 +369,13 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => { loadAsMap(XLIFF); }).toThrowError(/<unit> misses the "id" attribute/);
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/<unit> misses the "id" attribute/);
|
||||
});
|
||||
|
||||
it('should throw on duplicate unit id', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
it('should throw on duplicate unit id', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en">
|
||||
<file original="ng.template" id="ngi18n">
|
||||
<unit id="deadbeef">
|
||||
@ -389,15 +393,15 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/Duplicated translations for msg deadbeef/);
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/Duplicated translations for msg deadbeef/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('message errors', () => {
|
||||
it('should throw on unknown message tags', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
describe('message errors', () => {
|
||||
it('should throw on unknown message tags', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en">
|
||||
<file original="ng.template" id="ngi18n">
|
||||
<unit id="deadbeef">
|
||||
@ -409,13 +413,15 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => { loadAsMap(XLIFF); })
|
||||
.toThrowError(new RegExp(
|
||||
escapeRegExp(`[ERROR ->]<b>msg should contain only ph and pc tags</b>`)));
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
})
|
||||
.toThrowError(
|
||||
new RegExp(escapeRegExp(`[ERROR ->]<b>msg should contain only ph and pc tags</b>`)));
|
||||
});
|
||||
|
||||
it('should throw when a placeholder misses an id attribute', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
it('should throw when a placeholder misses an id attribute', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en">
|
||||
<file original="ng.template" id="ngi18n">
|
||||
<unit id="deadbeef">
|
||||
@ -427,10 +433,10 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(new RegExp(escapeRegExp(`<ph> misses the "equiv" attribute`)));
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(new RegExp(escapeRegExp(`<ph> misses the "equiv" attribute`)));
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
@ -241,63 +241,67 @@ lignes</target>
|
||||
`;
|
||||
|
||||
(function() {
|
||||
const serializer = new Xliff();
|
||||
const serializer = new Xliff();
|
||||
|
||||
function toXliff(html: string, locale: string | null = null): string {
|
||||
const catalog = new MessageBundle(new HtmlParser, [], {}, locale);
|
||||
catalog.updateFromTemplate(html, 'file.ts', DEFAULT_INTERPOLATION_CONFIG);
|
||||
return catalog.write(serializer);
|
||||
}
|
||||
function toXliff(html: string, locale: string|null = null): string {
|
||||
const catalog = new MessageBundle(new HtmlParser, [], {}, locale);
|
||||
catalog.updateFromTemplate(html, 'file.ts', DEFAULT_INTERPOLATION_CONFIG);
|
||||
return catalog.write(serializer);
|
||||
}
|
||||
|
||||
function loadAsMap(xliff: string): {[id: string]: string} {
|
||||
const {i18nNodesByMsgId} = serializer.load(xliff, 'url');
|
||||
function loadAsMap(xliff: string): {[id: string]: string} {
|
||||
const {i18nNodesByMsgId} = serializer.load(xliff, 'url');
|
||||
|
||||
const msgMap: {[id: string]: string} = {};
|
||||
Object.keys(i18nNodesByMsgId)
|
||||
.forEach(id => msgMap[id] = serializeNodes(i18nNodesByMsgId[id]).join(''));
|
||||
const msgMap: {[id: string]: string} = {};
|
||||
Object.keys(i18nNodesByMsgId)
|
||||
.forEach(id => msgMap[id] = serializeNodes(i18nNodesByMsgId[id]).join(''));
|
||||
|
||||
return msgMap;
|
||||
}
|
||||
return msgMap;
|
||||
}
|
||||
|
||||
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('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', () => {
|
||||
it('should load XLIFF files', () => {
|
||||
expect(loadAsMap(LOAD_XLIFF)).toEqual({
|
||||
'983775b9a51ce14b036be72d4cfd65d68d64e231': 'etubirtta elbatalsnart',
|
||||
'ec1d033f2436133c14ab038286c4f5df4697484a':
|
||||
'<ph name="INTERPOLATION"/> footnemele elbatalsnart <ph name="START_BOLD_TEXT"/>sredlohecalp htiw<ph name="CLOSE_BOLD_TEXT"/>',
|
||||
'e2ccf3d131b15f54aa1fcf1314b1ca77c14bfcc2':
|
||||
'{VAR_PLURAL, plural, =0 {[<ph name="START_PARAGRAPH"/>, TEST, <ph name="CLOSE_PARAGRAPH"/>]}}',
|
||||
'db3e0a6a5a96481f60aec61d98c3eecddef5ac23': 'oof',
|
||||
'i': 'toto',
|
||||
'bar': 'tata',
|
||||
'd7fa2d59aaedcaa5309f13028c59af8c85b8c49d':
|
||||
'<ph name="START_TAG_DIV"/><ph name="CLOSE_TAG_DIV"/><ph name="TAG_IMG"/><ph name="LINE_BREAK"/>',
|
||||
'empty target': '',
|
||||
'baz':
|
||||
'{VAR_PLURAL, plural, =0 {[{VAR_SELECT, select, other {[<ph name="START_PARAGRAPH"/>, profondément imbriqué, <ph name="CLOSE_PARAGRAPH"/>]}}, ]}}',
|
||||
'52ffa620dcd76247a56d5331f34e73f340a43cdb': 'Test: <ph name="ICU"/>',
|
||||
'1503afd0ccc20ff01d5e2266a9157b7b342ba494':
|
||||
'{VAR_PLURAL, plural, =0 {[{VAR_SELECT, select, other {[<ph' +
|
||||
' name="START_PARAGRAPH"/>, profondément imbriqué, <ph name="CLOSE_PARAGRAPH"/>]}}, ]}, =other {[beaucoup]}}',
|
||||
'fcfa109b0e152d4c217dbc02530be0bcb8123ad1': `multi
|
||||
lignes`,
|
||||
'mrk-test': 'Translated first sentence.',
|
||||
'mrk-test2': 'Translated first sentence.'
|
||||
});
|
||||
});
|
||||
|
||||
describe('load', () => {
|
||||
it('should load XLIFF files', () => {
|
||||
expect(loadAsMap(LOAD_XLIFF)).toEqual({
|
||||
'983775b9a51ce14b036be72d4cfd65d68d64e231': 'etubirtta elbatalsnart',
|
||||
'ec1d033f2436133c14ab038286c4f5df4697484a':
|
||||
'<ph name="INTERPOLATION"/> footnemele elbatalsnart <ph name="START_BOLD_TEXT"/>sredlohecalp htiw<ph name="CLOSE_BOLD_TEXT"/>',
|
||||
'e2ccf3d131b15f54aa1fcf1314b1ca77c14bfcc2':
|
||||
'{VAR_PLURAL, plural, =0 {[<ph name="START_PARAGRAPH"/>, TEST, <ph name="CLOSE_PARAGRAPH"/>]}}',
|
||||
'db3e0a6a5a96481f60aec61d98c3eecddef5ac23': 'oof',
|
||||
'i': 'toto',
|
||||
'bar': 'tata',
|
||||
'd7fa2d59aaedcaa5309f13028c59af8c85b8c49d':
|
||||
'<ph name="START_TAG_DIV"/><ph name="CLOSE_TAG_DIV"/><ph name="TAG_IMG"/><ph name="LINE_BREAK"/>',
|
||||
'empty target': '',
|
||||
'baz':
|
||||
'{VAR_PLURAL, plural, =0 {[{VAR_SELECT, select, other {[<ph name="START_PARAGRAPH"/>, profondément imbriqué, <ph name="CLOSE_PARAGRAPH"/>]}}, ]}}',
|
||||
'52ffa620dcd76247a56d5331f34e73f340a43cdb': 'Test: <ph name="ICU"/>',
|
||||
'1503afd0ccc20ff01d5e2266a9157b7b342ba494':
|
||||
'{VAR_PLURAL, plural, =0 {[{VAR_SELECT, select, other {[<ph' +
|
||||
' name="START_PARAGRAPH"/>, profondément imbriqué, <ph name="CLOSE_PARAGRAPH"/>]}}, ]}, =other {[beaucoup]}}',
|
||||
'fcfa109b0e152d4c217dbc02530be0bcb8123ad1': `multi
|
||||
lignes`,
|
||||
'mrk-test': 'Translated first sentence.',
|
||||
'mrk-test2': 'Translated first sentence.'
|
||||
});
|
||||
});
|
||||
it('should return the target locale', () => {
|
||||
expect(serializer.load(LOAD_XLIFF, 'url').locale).toEqual('fr');
|
||||
});
|
||||
|
||||
it('should return the target locale',
|
||||
() => { expect(serializer.load(LOAD_XLIFF, 'url').locale).toEqual('fr'); });
|
||||
|
||||
it('should ignore alt-trans targets', () => {
|
||||
const XLIFF = `
|
||||
it('should ignore alt-trans targets', () => {
|
||||
const XLIFF = `
|
||||
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<file source-language="en" target-language="fr" datatype="plaintext" original="ng2.template">
|
||||
<body>
|
||||
@ -318,12 +322,12 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(loadAsMap(XLIFF)).toEqual({'registration.submit': 'Weiter'});
|
||||
});
|
||||
expect(loadAsMap(XLIFF)).toEqual({'registration.submit': 'Weiter'});
|
||||
});
|
||||
|
||||
describe('structure errors', () => {
|
||||
it('should throw when a trans-unit has no translation', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
describe('structure errors', () => {
|
||||
it('should throw when a trans-unit has no translation', () => {
|
||||
const 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">
|
||||
<body>
|
||||
@ -334,14 +338,14 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/Message missingtarget misses a translation/);
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/Message missingtarget misses a translation/);
|
||||
});
|
||||
|
||||
|
||||
it('should throw when a trans-unit has no id attribute', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
it('should throw when a trans-unit has no id attribute', () => {
|
||||
const 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">
|
||||
<body>
|
||||
@ -353,13 +357,13 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/<trans-unit> misses the "id" attribute/);
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/<trans-unit> misses the "id" attribute/);
|
||||
});
|
||||
|
||||
it('should throw on duplicate trans-unit id', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
it('should throw on duplicate trans-unit id', () => {
|
||||
const 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">
|
||||
<body>
|
||||
@ -375,15 +379,15 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/Duplicated translations for msg deadbeef/);
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(/Duplicated translations for msg deadbeef/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('message errors', () => {
|
||||
it('should throw on unknown message tags', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
describe('message errors', () => {
|
||||
it('should throw on unknown message tags', () => {
|
||||
const 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">
|
||||
<body>
|
||||
@ -395,13 +399,15 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => { loadAsMap(XLIFF); })
|
||||
.toThrowError(
|
||||
new RegExp(escapeRegExp(`[ERROR ->]<b>msg should contain only ph tags</b>`)));
|
||||
});
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
})
|
||||
.toThrowError(
|
||||
new RegExp(escapeRegExp(`[ERROR ->]<b>msg should contain only ph tags</b>`)));
|
||||
});
|
||||
|
||||
it('should throw when a placeholder misses an id attribute', () => {
|
||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
it('should throw when a placeholder misses an id attribute', () => {
|
||||
const 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">
|
||||
<body>
|
||||
@ -413,12 +419,11 @@ lignes`,
|
||||
</file>
|
||||
</xliff>`;
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(new RegExp(escapeRegExp(`<x> misses the "id" attribute`)));
|
||||
});
|
||||
|
||||
expect(() => {
|
||||
loadAsMap(XLIFF);
|
||||
}).toThrowError(new RegExp(escapeRegExp(`<x> misses the "id" attribute`)));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
@ -76,7 +76,7 @@ lines</msg>
|
||||
});
|
||||
}
|
||||
|
||||
function toXmb(html: string, url: string, locale: string | null = null): string {
|
||||
function toXmb(html: string, url: string, locale: string|null = null): string {
|
||||
const catalog = new MessageBundle(new HtmlParser, [], {}, locale);
|
||||
const serializer = new Xmb();
|
||||
|
||||
|
@ -15,11 +15,13 @@ import * as xml from '../../../src/i18n/serializers/xml_helper';
|
||||
.toEqual('<?xml version="1.0" ?>');
|
||||
});
|
||||
|
||||
it('should serialize text node',
|
||||
() => { expect(xml.serialize([new xml.Text('foo bar')])).toEqual('foo bar'); });
|
||||
it('should serialize text node', () => {
|
||||
expect(xml.serialize([new xml.Text('foo bar')])).toEqual('foo bar');
|
||||
});
|
||||
|
||||
it('should escape text nodes',
|
||||
() => { expect(xml.serialize([new xml.Text('<>')])).toEqual('<>'); });
|
||||
it('should escape text nodes', () => {
|
||||
expect(xml.serialize([new xml.Text('<>')])).toEqual('<>');
|
||||
});
|
||||
|
||||
it('should serialize xml nodes without children', () => {
|
||||
expect(xml.serialize([new xml.Tag('el', {foo: 'bar'}, [])])).toEqual('<el foo="bar"/>');
|
||||
@ -42,6 +44,5 @@ import * as xml from '../../../src/i18n/serializers/xml_helper';
|
||||
expect(xml.serialize([new xml.Tag('el', {foo: '<">'}, [])]))
|
||||
.toEqual('<el foo="<">"/>');
|
||||
});
|
||||
|
||||
});
|
||||
}
|
@ -117,7 +117,7 @@ import {Xtb} from '../../../src/i18n/serializers/xtb';
|
||||
</translationbundle>`;
|
||||
|
||||
// Invalid messages should not cause the parser to throw
|
||||
let i18nNodesByMsgId: {[id: string]: i18n.Node[]} = undefined !;
|
||||
let i18nNodesByMsgId: {[id: string]: i18n.Node[]} = undefined!;
|
||||
expect(() => {
|
||||
i18nNodesByMsgId = serializer.load(XTB, 'url').i18nNodesByMsgId;
|
||||
}).not.toThrow();
|
||||
@ -144,7 +144,9 @@ import {Xtb} from '../../../src/i18n/serializers/xtb';
|
||||
<translation></translation>
|
||||
</translationbundle>`;
|
||||
|
||||
expect(() => { loadAsMap(XTB); }).toThrowError(/<translation> misses the "id" attribute/);
|
||||
expect(() => {
|
||||
loadAsMap(XTB);
|
||||
}).toThrowError(/<translation> misses the "id" attribute/);
|
||||
});
|
||||
|
||||
it('should throw when a placeholder has no name attribute', () => {
|
||||
@ -152,7 +154,9 @@ import {Xtb} from '../../../src/i18n/serializers/xtb';
|
||||
<translation id="1186013544048295927"><ph /></translation>
|
||||
</translationbundle>`;
|
||||
|
||||
expect(() => { loadAsMap(XTB); }).toThrowError(/<ph> misses the "name" attribute/);
|
||||
expect(() => {
|
||||
loadAsMap(XTB);
|
||||
}).toThrowError(/<ph> misses the "name" attribute/);
|
||||
});
|
||||
|
||||
it('should throw on unknown xtb tags', () => {
|
||||
@ -168,7 +172,9 @@ import {Xtb} from '../../../src/i18n/serializers/xtb';
|
||||
<translation id="1186013544048295927"><b>msg should contain only ph tags</b></translation>
|
||||
</translationbundle>`;
|
||||
|
||||
expect(() => { loadAsMap(XTB); })
|
||||
expect(() => {
|
||||
loadAsMap(XTB);
|
||||
})
|
||||
.toThrowError(
|
||||
new RegExp(escapeRegExp(`[ERROR ->]<b>msg should contain only ph tags</b>`)));
|
||||
});
|
||||
@ -184,9 +190,11 @@ import {Xtb} from '../../../src/i18n/serializers/xtb';
|
||||
}).toThrowError(/Duplicated translations for msg 1186013544048295927/);
|
||||
});
|
||||
|
||||
it('should throw when trying to save an xtb file',
|
||||
() => { expect(() => { serializer.write([], null); }).toThrowError(/Unsupported/); });
|
||||
|
||||
it('should throw when trying to save an xtb file', () => {
|
||||
expect(() => {
|
||||
serializer.write([], null);
|
||||
}).toThrowError(/Unsupported/);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -25,14 +25,14 @@ import {_extractMessages} from './i18n_parser_spec';
|
||||
const srcNode = new i18n.Text('src', span);
|
||||
|
||||
it('should translate a plain text', () => {
|
||||
const msgMap = {foo: [new i18n.Text('bar', null !)]};
|
||||
const msgMap = {foo: [new i18n.Text('bar', null!)]};
|
||||
const tb = new TranslationBundle(msgMap, null, (_) => 'foo');
|
||||
const msg = new i18n.Message([srcNode], {}, {}, 'm', 'd', 'i');
|
||||
expect(serializeNodes(tb.get(msg))).toEqual(['bar']);
|
||||
});
|
||||
|
||||
it('should translate html-like plain text', () => {
|
||||
const msgMap = {foo: [new i18n.Text('<p>bar</p>', null !)]};
|
||||
const msgMap = {foo: [new i18n.Text('<p>bar</p>', null!)]};
|
||||
const tb = new TranslationBundle(msgMap, null, (_) => 'foo');
|
||||
const msg = new i18n.Message([srcNode], {}, {}, 'm', 'd', 'i');
|
||||
const nodes = tb.get(msg);
|
||||
@ -45,8 +45,8 @@ import {_extractMessages} from './i18n_parser_spec';
|
||||
it('should translate a message with placeholder', () => {
|
||||
const msgMap = {
|
||||
foo: [
|
||||
new i18n.Text('bar', null !),
|
||||
new i18n.Placeholder('', 'ph1', null !),
|
||||
new i18n.Text('bar', null!),
|
||||
new i18n.Placeholder('', 'ph1', null!),
|
||||
]
|
||||
};
|
||||
const phMap = {
|
||||
@ -60,12 +60,12 @@ import {_extractMessages} from './i18n_parser_spec';
|
||||
it('should translate a message with placeholder referencing messages', () => {
|
||||
const msgMap = {
|
||||
foo: [
|
||||
new i18n.Text('--', null !),
|
||||
new i18n.Placeholder('', 'ph1', null !),
|
||||
new i18n.Text('++', null !),
|
||||
new i18n.Text('--', null!),
|
||||
new i18n.Placeholder('', 'ph1', null!),
|
||||
new i18n.Text('++', null!),
|
||||
],
|
||||
ref: [
|
||||
new i18n.Text('*refMsg*', null !),
|
||||
new i18n.Text('*refMsg*', null!),
|
||||
],
|
||||
};
|
||||
const refMsg = new i18n.Message([srcNode], {}, {}, 'm', 'd', 'i');
|
||||
@ -84,13 +84,13 @@ import {_extractMessages} from './i18n_parser_spec';
|
||||
|
||||
const digest = (_: any) => `no matching id`;
|
||||
// Empty message map -> use source messages in Ignore mode
|
||||
let tb = new TranslationBundle({}, null, digest, null !, MissingTranslationStrategy.Ignore);
|
||||
let tb = new TranslationBundle({}, null, digest, null!, MissingTranslationStrategy.Ignore);
|
||||
expect(serializeNodes(tb.get(messages[0])).join('')).toEqual(src);
|
||||
// Empty message map -> use source messages in Warning mode
|
||||
tb = new TranslationBundle({}, null, digest, null !, MissingTranslationStrategy.Warning);
|
||||
tb = new TranslationBundle({}, null, digest, null!, MissingTranslationStrategy.Warning);
|
||||
expect(serializeNodes(tb.get(messages[0])).join('')).toEqual(src);
|
||||
// Empty message map -> throw in Error mode
|
||||
tb = new TranslationBundle({}, null, digest, null !, MissingTranslationStrategy.Error);
|
||||
tb = new TranslationBundle({}, null, digest, null!, MissingTranslationStrategy.Error);
|
||||
expect(() => serializeNodes(tb.get(messages[0])).join('')).toThrow();
|
||||
});
|
||||
|
||||
@ -98,7 +98,7 @@ import {_extractMessages} from './i18n_parser_spec';
|
||||
it('should report unknown placeholders', () => {
|
||||
const msgMap = {
|
||||
foo: [
|
||||
new i18n.Text('bar', null !),
|
||||
new i18n.Text('bar', null!),
|
||||
new i18n.Placeholder('', 'ph1', span),
|
||||
]
|
||||
};
|
||||
@ -109,7 +109,7 @@ import {_extractMessages} from './i18n_parser_spec';
|
||||
|
||||
it('should report missing translation', () => {
|
||||
const tb =
|
||||
new TranslationBundle({}, null, (_) => 'foo', null !, MissingTranslationStrategy.Error);
|
||||
new TranslationBundle({}, null, (_) => 'foo', null!, MissingTranslationStrategy.Error);
|
||||
const msg = new i18n.Message([srcNode], {}, {}, 'm', 'd', 'i');
|
||||
expect(() => tb.get(msg)).toThrowError(/Missing translation for message "foo"/);
|
||||
});
|
||||
@ -117,12 +117,14 @@ import {_extractMessages} from './i18n_parser_spec';
|
||||
it('should report missing translation with MissingTranslationStrategy.Warning', () => {
|
||||
const log: string[] = [];
|
||||
const console = {
|
||||
log: (msg: string) => { throw `unexpected`; },
|
||||
log: (msg: string) => {
|
||||
throw `unexpected`;
|
||||
},
|
||||
warn: (msg: string) => log.push(msg),
|
||||
};
|
||||
|
||||
const tb = new TranslationBundle(
|
||||
{}, 'en', (_) => 'foo', null !, MissingTranslationStrategy.Warning, console);
|
||||
{}, 'en', (_) => 'foo', null!, MissingTranslationStrategy.Warning, console);
|
||||
const msg = new i18n.Message([srcNode], {}, {}, 'm', 'd', 'i');
|
||||
|
||||
expect(() => tb.get(msg)).not.toThrowError();
|
||||
@ -131,8 +133,8 @@ import {_extractMessages} from './i18n_parser_spec';
|
||||
});
|
||||
|
||||
it('should not report missing translation with MissingTranslationStrategy.Ignore', () => {
|
||||
const tb = new TranslationBundle(
|
||||
{}, null, (_) => 'foo', null !, MissingTranslationStrategy.Ignore);
|
||||
const tb =
|
||||
new TranslationBundle({}, null, (_) => 'foo', null!, MissingTranslationStrategy.Ignore);
|
||||
const msg = new i18n.Message([srcNode], {}, {}, 'm', 'd', 'i');
|
||||
expect(() => tb.get(msg)).not.toThrowError();
|
||||
});
|
||||
@ -146,15 +148,15 @@ import {_extractMessages} from './i18n_parser_spec';
|
||||
let count = 0;
|
||||
const digest = (_: any) => count++ ? 'ref' : 'foo';
|
||||
const tb =
|
||||
new TranslationBundle(msgMap, null, digest, null !, MissingTranslationStrategy.Error);
|
||||
new TranslationBundle(msgMap, null, digest, null!, MissingTranslationStrategy.Error);
|
||||
expect(() => tb.get(msg)).toThrowError(/Missing translation for message "ref"/);
|
||||
});
|
||||
|
||||
it('should report invalid translated html', () => {
|
||||
const msgMap = {
|
||||
foo: [
|
||||
new i18n.Text('text', null !),
|
||||
new i18n.Placeholder('', 'ph1', null !),
|
||||
new i18n.Text('text', null!),
|
||||
new i18n.Placeholder('', 'ph1', null!),
|
||||
]
|
||||
};
|
||||
const phMap = {
|
||||
|
Reference in New Issue
Block a user