ngx-i18nsupport-lib
Version:
A Typescript library to work with Angular generated i18n files (xliff, xmb)
436 lines • 27.8 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var api_1 = require("../api");
var fs = require("fs");
var xmldom_1 = require("xmldom");
var dom_utilities_1 = require("./dom-utilities");
/**
* Created by martin on 28.04.2017.
* Testcases for xmb files.
*/
describe('ngx-i18nsupport-lib xtb test spec', function () {
var SRCDIR = 'test/testdata/i18n/';
var ENCODING = 'UTF-8';
/**
* Helper function to read Xtb from 2 Files, the xtb and the master
* @type {string}
*/
function readFile(path, masterPath) {
var content = fs.readFileSync(path, ENCODING);
if (masterPath) {
var masterContent = fs.readFileSync(masterPath, ENCODING);
var optionalMaster = { xmlContent: masterContent, path: masterPath, encoding: ENCODING };
return api_1.TranslationMessagesFileFactory.fromFileContent('xtb', content, path, ENCODING, optionalMaster);
}
else {
return api_1.TranslationMessagesFileFactory.fromFileContent('xtb', content, path, ENCODING, null);
}
}
/**
* Helper function to read file with unknown format
* @type {string}
*/
function readUnknownFormatFile(path, masterPath) {
var content = fs.readFileSync(path, ENCODING);
if (masterPath) {
var masterContent = fs.readFileSync(masterPath, ENCODING);
var optionalMaster = { xmlContent: masterContent, path: masterPath, encoding: ENCODING };
return api_1.TranslationMessagesFileFactory.fromUnknownFormatFileContent(content, path, ENCODING, optionalMaster);
}
else {
return api_1.TranslationMessagesFileFactory.fromUnknownFormatFileContent(content, path, ENCODING, null);
}
}
describe('xtb format tests', function () {
var MASTER_1_XMB = SRCDIR + 'ngExtractedMaster1.xmb';
var MASTER_DE_XMB = SRCDIR + 'ngExtractedMaster1.de.xmb';
var TRANSLATION_EN_XTB = SRCDIR + 'ngExtractedMaster1.en.xtb';
var ID_MY_FIRST = '2047558209369508311'; // an ID from ngExtractedMaster1.xmb
var ID_WITH_PLACEHOLDER = '9030312858648510700';
var ID_WITH_MEANING_AND_DESCRIPTION = '3274258156935474372'; // ID with placeholders and source element
var ID_WITH_NO_SOURCEREFS = 'no_sourceref_test'; // an ID with no source elements
var ID_WITH_TWO_SOURCEREFS = '4371668001355139802'; // an ID with 2 source elements
var ID_WITH_LINEBREAK = '7149517499881679376';
var ID_WITH_TAGS = '7609655310648429098';
var ID_WITH_TAG_STRANGE = '7610784844464920497';
var ID_TO_MERGE = 'unittomerge';
var ID_ICU_PLURAL = '157616252019374389';
var ID_ICU_SELECT = '4002068837191765530';
var ID_ICU_SELECT_2 = '4002068837191765531';
var ID_ICU_EMBEDDED_TAGS = '6710804210857077393';
var ID_CONTAINS_ICU = '2747218257718409559';
var ID_CONTAINS_TWO_ICU = 'complextags.icuTwoICU';
var ID_WITH_BR_TAG = '3944017551463298929';
var ID_WITH_IMG_TAG = '705837031073461246';
var ID_UNTRANSLATED_DESCRIPTION = '7499557905529977372';
it('should read xtb file', function () {
var file = readFile(TRANSLATION_EN_XTB);
expect(file).toBeTruthy();
expect(file.fileType()).toBe('XTB');
var tu = file.transUnitWithId(ID_MY_FIRST);
expect(tu).toBeTruthy();
expect(tu.sourceContent()).toBeFalsy();
expect(tu.targetContent()).toBe('My first I18N Application');
});
it('should emit warnings', function () {
var file = readFile(TRANSLATION_EN_XTB);
expect(file.warnings().length).toBe(1);
expect(file.warnings()[0]).toContain('msg without "id"');
});
it('should emit warnings, if master does not fit', function () {
var file = readUnknownFormatFile(TRANSLATION_EN_XTB, MASTER_1_XMB);
expect(file.warnings().length).toBe(2);
expect(file.warnings()[0]).toContain('msg without "id"');
expect(file.warnings()[1]).toContain('Check if it is the correct master');
});
it('should count units', function () {
var file = readFile(TRANSLATION_EN_XTB);
expect(file.numberOfTransUnits()).toBe(18);
expect(file.numberOfTransUnitsWithMissingId()).toBe(1);
expect(file.numberOfUntranslatedTransUnits()).toBe(file.numberOfTransUnits());
expect(file.numberOfReviewedTransUnits()).toBe(0);
});
it('should return source language', function () {
var file = readFile(TRANSLATION_EN_XTB);
expect(file.sourceLanguage()).toBeFalsy(); // no master, no source!
var file2 = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
expect(file2.sourceLanguage()).toBe('de');
});
it('should return target language', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
expect(file.targetLanguage()).toBe('en');
});
it('should loop over all trans units', function () {
var translatedFile = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var count = 0;
translatedFile.forEachTransUnit(function (tu) {
expect(tu).toBeTruthy();
count++;
});
expect(count).toBeGreaterThan(4);
});
it('should ignore change source content', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_WITH_BR_TAG);
expect(tu).toBeTruthy();
expect(tu.sourceContent()).toBeTruthy();
var oldValue = tu.sourceContent();
expect(tu.supportsSetSourceContent()).toBeFalsy();
var changedMessage = 'a changed source';
tu.setSourceContent(changedMessage);
expect(tu.sourceContent()).toBe(oldValue);
});
it('should read meaning and description of tu', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_WITH_MEANING_AND_DESCRIPTION);
expect(tu).toBeTruthy();
expect(tu.meaning()).toBe('dateservice.monday');
expect(tu.description()).toBe('ngx-translate');
});
it('should ignore change description', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_WITH_MEANING_AND_DESCRIPTION);
expect(tu).toBeTruthy();
expect(tu.description()).toBeTruthy();
var oldValue = tu.description();
expect(tu.supportsSetDescriptionAndMeaning()).toBeFalsy();
var changedMessage = 'a changed description';
tu.setDescription(changedMessage);
expect(tu.description()).toBe(oldValue);
});
it('should ignore change meaning', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_WITH_MEANING_AND_DESCRIPTION);
expect(tu).toBeTruthy();
expect(tu.meaning()).toBeTruthy();
var oldValue = tu.meaning();
expect(tu.supportsSetDescriptionAndMeaning()).toBeFalsy();
var changedMessage = 'a changed description';
tu.setMeaning(changedMessage);
expect(tu.meaning()).toBe(oldValue);
});
it('should ignore source attribute in sourceContent', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_WITH_PLACEHOLDER);
expect(tu).toBeTruthy();
expect(tu.sourceContent()).toBe('Eintrag <ph name="INTERPOLATION"><ex>INTERPOLATION</ex></ph> von <ph name="INTERPOLATION_1"><ex>INTERPOLATION_1</ex></ph> hinzugefügt.');
});
it('should return empty source references array if source not set', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_WITH_NO_SOURCEREFS);
expect(tu).toBeTruthy();
expect(tu.sourceReferences().length).toBe(0);
});
it('should return source reference', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_WITH_PLACEHOLDER);
expect(tu).toBeTruthy();
expect(tu.sourceReferences().length).toBe(1);
expect(tu.sourceReferences()[0].sourcefile).toBe('S:/experimente/sampleapp41/src/app/app.component.ts');
expect(tu.sourceReferences()[0].linenumber).toBe(6);
});
it('should return more than one source references', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_WITH_TWO_SOURCEREFS);
expect(tu).toBeTruthy();
expect(tu.sourceReferences().length).toBe(2);
expect(tu.sourceReferences()[0].sourcefile).toBe('S:/experimente/sampleapp41/src/app/app.component.ts');
expect(tu.sourceReferences()[0].linenumber).toBe(2);
expect(tu.sourceReferences()[1].sourcefile).toBe('S:/experimente/sampleapp41/src/app/app.component.ts');
expect(tu.sourceReferences()[1].linenumber).toBe(3);
});
it('should return source reference with more than 1 linenumber', function () {
// if the text in template spreads over more than 1 line, there is a linenumber format like 7,8 used
// in this case, linenumber is the first line (here 7).
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_WITH_LINEBREAK);
expect(tu).toBeTruthy();
expect(tu.sourceReferences().length).toBe(1);
expect(tu.sourceReferences()[0].sourcefile).toBe('S:/experimente/sampleapp41/src/app/app.component.ts');
expect(tu.sourceReferences()[0].linenumber).toBe(7);
});
it('should run through 3 different states while translating', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_MY_FIRST);
expect(tu).toBeTruthy();
expect(tu.targetState()).toBe(api_1.STATE_FINAL);
// TODO state handling xmb to be improved
tu.translate('');
expect(tu.targetState()).toBe(api_1.STATE_NEW);
tu.translate('a translation');
expect(tu.targetState()).toBe(api_1.STATE_FINAL);
});
it('should not change source reference, because it is not supported in xtb', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_WITH_TWO_SOURCEREFS);
expect(tu).toBeTruthy();
expect(tu.sourceReferences().length).toBe(2);
expect(tu.supportsSetSourceReferences()).toBeFalsy();
tu.setSourceReferences([{ sourcefile: 'x', linenumber: 1 }]);
expect(tu.sourceReferences().length).toBe(2); // shall be unchanged
var masterContent = { xmlContent: fs.readFileSync(MASTER_DE_XMB, ENCODING), path: MASTER_DE_XMB, encoding: 'UTF-8' };
var file2 = api_1.TranslationMessagesFileFactory.fromUnknownFormatFileContent(file.editedContent(), null, null, masterContent);
var tu2 = file2.transUnitWithId(ID_WITH_TWO_SOURCEREFS);
expect(tu2.sourceReferences().length).toBe(2);
expect(tu2.sourceReferences()[0].sourcefile).toBe('S:/experimente/sampleapp41/src/app/app.component.ts');
expect(tu2.sourceReferences()[0].linenumber).toBe(2);
expect(tu2.sourceReferences()[1].sourcefile).toBe('S:/experimente/sampleapp41/src/app/app.component.ts');
expect(tu2.sourceReferences()[1].linenumber).toBe(3);
});
it('should not change source reference when translating', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_WITH_TWO_SOURCEREFS);
expect(tu).toBeTruthy();
expect(tu.sourceReferences().length).toBe(2);
tu.translate('a translated value');
var masterContent = { xmlContent: fs.readFileSync(MASTER_DE_XMB, ENCODING), path: MASTER_DE_XMB, encoding: 'UTF-8' };
var file2 = api_1.TranslationMessagesFileFactory.fromUnknownFormatFileContent(file.editedContent(), null, null, masterContent);
var tu2 = file2.transUnitWithId(ID_WITH_TWO_SOURCEREFS);
expect(tu2.targetContent()).toBe('a translated value');
expect(tu2.sourceReferences().length).toBe(2);
expect(tu2.sourceReferences()[0].sourcefile).toBe('S:/experimente/sampleapp41/src/app/app.component.ts');
expect(tu2.sourceReferences()[0].linenumber).toBe(2);
expect(tu2.sourceReferences()[1].sourcefile).toBe('S:/experimente/sampleapp41/src/app/app.component.ts');
expect(tu2.sourceReferences()[1].linenumber).toBe(3);
});
it('should normalize placeholders to {{0}} etc', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_WITH_PLACEHOLDER);
expect(tu.targetContentNormalized().asDisplayString()).toBe('Entry {{0}} of {{1}} added.');
});
it('should normalize embedded html tags', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_WITH_TAGS);
expect(tu.targetContentNormalized().asDisplayString()).toBe('This message is <b><strong>VERY IMPORTANT</strong></b>');
});
it('should normalize embedded html tags', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_WITH_TAG_STRANGE);
expect(tu.targetContentNormalized().asDisplayString()).toBe('This message is <strange>{{0}}</strange>');
});
it('should normalize empty html tag br', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_WITH_BR_TAG);
expect(tu.sourceContentNormalized().asDisplayString()).toBe('Dieser Text enthält<br>einen Zeilenumbruch per HTML-br-Element.');
var translation = tu.sourceContentNormalized().translate('This text contains<br> a linebreak');
tu.translate(translation);
expect(tu.targetContent()).toBe('This text contains<ph name="LINE_BREAK"><ex><br></ex></ph> a linebreak');
});
it('should normalize empty html tag img', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_WITH_IMG_TAG);
expect(tu.sourceContentNormalized().asDisplayString()).toBe('Dieser Text enthält ein Bild <img> mitt en in der Nachricht');
var translation = tu.sourceContentNormalized().translate('This text contains an img <img> in the message');
tu.translate(translation);
expect(tu.targetContent()).toBe('This text contains an img <ph name="TAG_IMG"><ex><img></ex></ph> in the message');
});
it('should remove a transunit by id', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_WITH_TWO_SOURCEREFS);
expect(tu).toBeTruthy();
file.removeTransUnitWithId(ID_WITH_TWO_SOURCEREFS);
var file2 = api_1.TranslationMessagesFileFactory.fromUnknownFormatFileContent(file.editedContent(), null, null);
var tu2 = file2.transUnitWithId(ID_WITH_TWO_SOURCEREFS);
expect(tu2).toBeFalsy(); // should not exist any more
});
it('should copy a transunit from file a to file b', function () {
var file = readUnknownFormatFile(MASTER_1_XMB);
var tu = file.transUnitWithId(ID_TO_MERGE);
expect(tu).toBeTruthy();
var targetFile = readFile(TRANSLATION_EN_XTB, MASTER_1_XMB);
expect(targetFile.transUnitWithId(ID_TO_MERGE)).toBeFalsy();
var newTu = targetFile.importNewTransUnit(tu, false, true);
expect(targetFile.transUnitWithId(ID_TO_MERGE)).toBeTruthy();
expect(targetFile.transUnitWithId(ID_TO_MERGE)).toEqual(newTu);
var changedTargetFile = api_1.TranslationMessagesFileFactory.fromUnknownFormatFileContent(targetFile.editedContent(), null, null);
var targetTu = changedTargetFile.transUnitWithId(ID_TO_MERGE);
expect(targetTu.targetContent()).toBe('Test for merging units');
});
it('should not copy source to target for non default lang if not wanted', function () {
var file = readUnknownFormatFile(MASTER_1_XMB);
var tu = file.transUnitWithId(ID_UNTRANSLATED_DESCRIPTION);
expect(tu).toBeTruthy();
var isDefaultLang = false;
var copyContent = false;
var file2 = file.createTranslationFileForLang('xy', null, isDefaultLang, copyContent);
var changedTargetFile = api_1.TranslationMessagesFileFactory.fromUnknownFormatFileContent(file2.editedContent(), null, null);
var tu2a = changedTargetFile.transUnitWithId(ID_UNTRANSLATED_DESCRIPTION);
expect(tu2a.targetContent()).toBeFalsy();
var tu2 = file2.transUnitWithId(ID_UNTRANSLATED_DESCRIPTION);
expect(tu2.targetContent()).toBeFalsy();
});
it('should copy a transunit from file a to file b and leave content blank (xliffmerge #103)', function () {
var file = readUnknownFormatFile(MASTER_1_XMB);
var tu = file.transUnitWithId(ID_TO_MERGE);
expect(tu).toBeTruthy();
var targetFile = readFile(TRANSLATION_EN_XTB, MASTER_1_XMB);
expect(targetFile.transUnitWithId(ID_TO_MERGE)).toBeFalsy();
// flag copyContent set to false here...
var newTu = targetFile.importNewTransUnit(tu, false, false);
expect(targetFile.transUnitWithId(ID_TO_MERGE)).toBeTruthy();
expect(targetFile.transUnitWithId(ID_TO_MERGE)).toEqual(newTu);
var changedTargetFile = api_1.TranslationMessagesFileFactory.fromUnknownFormatFileContent(targetFile.editedContent(), null, null);
var targetTu = changedTargetFile.transUnitWithId(ID_TO_MERGE);
expect(targetTu.targetContent()).toBe('');
});
it('should copy a transunit to a specified position (#53)', function () {
var file = readUnknownFormatFile(MASTER_1_XMB);
var tu = file.transUnitWithId(ID_TO_MERGE);
expect(tu).toBeTruthy();
var targetFile = readFile(TRANSLATION_EN_XTB, MASTER_1_XMB);
expect(targetFile.transUnitWithId(ID_TO_MERGE)).toBeFalsy();
var ID_EXISTING = '4371668001355139802';
var existingTu = targetFile.transUnitWithId(ID_EXISTING);
expect(existingTu).toBeTruthy();
var newTu = targetFile.importNewTransUnit(tu, false, true, existingTu);
expect(targetFile.transUnitWithId(ID_TO_MERGE)).toBeTruthy();
expect(targetFile.transUnitWithId(ID_TO_MERGE)).toEqual(newTu);
var doc = new xmldom_1.DOMParser().parseFromString(targetFile.editedContent());
var existingElem = dom_utilities_1.DOMUtilities.getElementByTagNameAndId(doc, 'translation', ID_EXISTING);
var newElem = dom_utilities_1.DOMUtilities.getElementByTagNameAndId(doc, 'translation', ID_TO_MERGE);
expect(dom_utilities_1.DOMUtilities.getElementFollowingSibling(existingElem)).toEqual(newElem);
var changedTargetFile = api_1.TranslationMessagesFileFactory.fromUnknownFormatFileContent(targetFile.editedContent(), null, null);
var targetTu = changedTargetFile.transUnitWithId(ID_TO_MERGE);
expect(targetTu.targetContent()).toBe('Test for merging units');
});
it('should copy a transunit to first position (#53)', function () {
var file = readUnknownFormatFile(MASTER_1_XMB);
var tu = file.transUnitWithId(ID_TO_MERGE);
expect(tu).toBeTruthy();
var targetFile = readFile(TRANSLATION_EN_XTB, MASTER_1_XMB);
expect(targetFile.transUnitWithId(ID_TO_MERGE)).toBeFalsy();
// when importNewTransUnit is called with null, new unit will be added at first position
var newTu = targetFile.importNewTransUnit(tu, false, true, null);
expect(targetFile.transUnitWithId(ID_TO_MERGE)).toBeTruthy();
expect(targetFile.transUnitWithId(ID_TO_MERGE)).toEqual(newTu);
var doc = new xmldom_1.DOMParser().parseFromString(targetFile.editedContent());
var newElem = dom_utilities_1.DOMUtilities.getElementByTagNameAndId(doc, 'translation', ID_TO_MERGE);
expect(newElem).toBeTruthy();
expect(dom_utilities_1.DOMUtilities.getElementPrecedingSibling(newElem)).toBeFalsy();
var changedTargetFile = api_1.TranslationMessagesFileFactory.fromUnknownFormatFileContent(targetFile.editedContent(), null, null);
var targetTu = changedTargetFile.transUnitWithId(ID_TO_MERGE);
expect(targetTu.targetContent()).toBe('Test for merging units');
});
it('should copy a transunit from file a to file b and set a praefix and suffix', function () {
var file = readUnknownFormatFile(MASTER_1_XMB);
var tu = file.transUnitWithId(ID_TO_MERGE);
expect(tu).toBeTruthy();
var targetFile = readFile(TRANSLATION_EN_XTB, MASTER_1_XMB);
targetFile.setNewTransUnitTargetPraefix('%%');
targetFile.setNewTransUnitTargetSuffix('!!');
expect(targetFile.transUnitWithId(ID_TO_MERGE)).toBeFalsy();
var newTu = targetFile.importNewTransUnit(tu, false, true);
expect(targetFile.transUnitWithId(ID_TO_MERGE)).toBeTruthy();
expect(targetFile.transUnitWithId(ID_TO_MERGE)).toEqual(newTu);
var changedTargetFile = api_1.TranslationMessagesFileFactory.fromUnknownFormatFileContent(targetFile.editedContent(), null, null);
var targetTu = changedTargetFile.transUnitWithId(ID_TO_MERGE);
expect(targetTu.targetContent()).toBe('%%Test for merging units!!');
});
it('should copy a transunit from file a to file b, but should not set a praefix and suffix for ICU messages', function () {
var file = readUnknownFormatFile(MASTER_1_XMB);
var tu = file.transUnitWithId(ID_ICU_SELECT_2);
expect(tu).toBeTruthy();
var targetFile = readFile(TRANSLATION_EN_XTB, MASTER_1_XMB);
targetFile.setNewTransUnitTargetPraefix('%%');
targetFile.setNewTransUnitTargetSuffix('!!');
expect(targetFile.transUnitWithId(ID_ICU_SELECT_2)).toBeFalsy();
var newTu = targetFile.importNewTransUnit(tu, false, true);
expect(targetFile.transUnitWithId(ID_ICU_SELECT_2)).toBeTruthy();
expect(targetFile.transUnitWithId(ID_ICU_SELECT_2)).toEqual(newTu);
var changedTargetFile = api_1.TranslationMessagesFileFactory.fromUnknownFormatFileContent(targetFile.editedContent(), null, null);
var targetTu = changedTargetFile.transUnitWithId(ID_ICU_SELECT_2);
expect(targetTu.targetContent()).not.toContain('%%');
expect(targetTu.targetContent()).not.toContain('!!');
});
it('should translate using NormalizedMessage (plain text case, no placeholders, no markup)', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_MY_FIRST);
expect(tu).toBeTruthy();
var translationString = 'Anwendung läuft';
// first translate
var translation = tu.sourceContentNormalized().translate(translationString);
tu.translate(translation);
expect(tu.targetContent()).toBe(translationString);
var file2 = api_1.TranslationMessagesFileFactory.fromUnknownFormatFileContent(file.editedContent(), null, null);
var tu2 = file2.transUnitWithId(ID_MY_FIRST);
expect(tu2.targetContentNormalized().asDisplayString()).toBe(translationString);
});
it('should translate plural ICU', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_ICU_PLURAL);
expect(tu).toBeTruthy();
var normalizedMessage = tu.sourceContentNormalized();
expect(normalizedMessage.asDisplayString()).toBe('<ICU-Message/>');
var translatedMessage = normalizedMessage.translateICUMessage({ '=0': 'nothing' });
tu.translate(translatedMessage);
var icuMessage = tu.targetContentNormalized().getICUMessage();
expect(icuMessage).toBeTruthy();
expect(icuMessage.isPluralMessage()).toBeTruthy();
expect(icuMessage.isSelectMessage()).toBeFalsy();
expect(icuMessage.getCategories().length).toBe(3);
expect(icuMessage.getCategories()[0].getCategory()).toBe('=0');
expect(icuMessage.getCategories()[0].getMessageNormalized().asDisplayString()).toBe('nothing');
expect(tu.targetContent()).toBe('{VAR_PLURAL, plural, =0 {nothing} =1 {1 Schaf} other {x Schafe}}');
});
it('should translate ICU with embedded tags', function () {
var file = readFile(TRANSLATION_EN_XTB, MASTER_DE_XMB);
var tu = file.transUnitWithId(ID_ICU_EMBEDDED_TAGS);
var normalizedMessage = tu.sourceContentNormalized();
expect(normalizedMessage.asDisplayString()).toBe('<ICU-Message/>');
var translatedMessage = normalizedMessage.translateICUMessage({ 'wert1': '<em>changed</em>' });
tu.translate(translatedMessage);
var icuMessage = tu.targetContentNormalized().getICUMessage();
expect(icuMessage).toBeTruthy();
expect(icuMessage.isPluralMessage()).toBeFalsy();
expect(icuMessage.isSelectMessage()).toBeTruthy();
expect(icuMessage.getCategories().length).toBe(3);
expect(icuMessage.getCategories()[1].getCategory()).toBe('wert1');
expect(icuMessage.getCategories()[1].getMessageNormalized().asDisplayString()).toBe('<em>changed</em>');
expect(tu.targetContent()).toContain('wert1 {<ph name="START_EMPHASISED_TEXT"><ex><em></ex></ph>changed<ph name="CLOSE_EMPHASISED_TEXT"><ex></em></ex></ph>}');
// TODO find warnings in embedded message, known limitation in the moment.
// const warnings = icuMessage.getCategories()[1].getMessageNormalized().validateWarnings();
// expect(warnings).toBeTruthy();
});
});
});
//# sourceMappingURL=S:/experimente/ngx-i18nsupport-lib/src/impl/xtb-file.spec.js.map