ngx-i18nsupport
Advanced tools
Comparing version 0.11.1 to 0.12.0
@@ -0,1 +1,9 @@ | ||
<a name="0.12.0"></a> | ||
# [0.12.0](https://github.com/martinroob/ngx-i18nsupport/compare/v0.12.0...v0.11.1) (2018-02-23) | ||
### Features | ||
* **xliffmerge:** Added support to add a prefix to translated target languages. | ||
<br>There are 2 new options `targetPraefix` and `targetSuffix` used for copied untranslated units ([#70](https://github.com/martinroob/ngx-i18nsupport/issues/70)). | ||
<a name="0.11.1"></a> | ||
@@ -2,0 +10,0 @@ # [0.11.1](https://github.com/martinroob/ngx-i18nsupport/compare/v0.11.1...v0.11.0) (2018-02-16) |
@@ -176,2 +176,45 @@ "use strict"; | ||
}); | ||
it('should generate translated file for all languages with set praefix and suffix (#70)', function (done) { | ||
file_util_1.FileUtil.copy(MASTER1SRC, MASTER); | ||
var ws = new writer_to_string_1.WriterToString(); | ||
var commandOut = new command_output_1.CommandOutput(ws); | ||
var profileContent = { | ||
xliffmergeOptions: { | ||
defaultLanguage: 'de', | ||
srcDir: WORKDIR, | ||
genDir: WORKDIR, | ||
i18nFile: MASTERFILE, | ||
targetPraefix: '%%', | ||
targetSuffix: '!!', | ||
} | ||
}; | ||
var xliffMergeCmd = xliff_merge_1.XliffMerge.createFromOptions(commandOut, { languages: ['de', 'en'] }, profileContent); | ||
xliffMergeCmd.run(); | ||
expect(ws.writtenData()).not.toContain('ERROR'); | ||
var langFileGerman = readXliff(xliffMergeCmd.generatedI18nFile('de')); | ||
expect(langFileGerman.sourceLanguage()).toBe('de'); | ||
expect(langFileGerman.targetLanguage()).toBe('de'); | ||
langFileGerman.forEachTransUnit(function (tu) { | ||
if (!tu.targetContent().startsWith('{VAR')) { | ||
expect(tu.targetContent()).toBe('%%' + tu.sourceContent() + '!!'); | ||
} | ||
else { | ||
expect(tu.targetContent()).toBe(tu.sourceContent()); | ||
} | ||
expect(tu.targetState()).toBe('final'); | ||
}); | ||
var langFileEnglish = readXliff(xliffMergeCmd.generatedI18nFile('en')); | ||
expect(langFileEnglish.sourceLanguage()).toBe('de'); | ||
expect(langFileEnglish.targetLanguage()).toBe('en'); | ||
langFileEnglish.forEachTransUnit(function (tu) { | ||
if (!tu.targetContent().startsWith('{VAR')) { | ||
expect(tu.targetContent()).toBe('%%' + tu.sourceContent() + '!!'); | ||
} | ||
else { | ||
expect(tu.targetContent()).toBe(tu.sourceContent()); | ||
} | ||
expect(tu.targetState()).toBe('new'); | ||
}); | ||
done(); | ||
}); | ||
it('should merge translated file for all languages', function (done) { | ||
@@ -178,0 +221,0 @@ file_util_1.FileUtil.copy(MASTER1SRC, MASTER); |
@@ -169,3 +169,3 @@ "use strict"; | ||
}); | ||
it('should generate translated file with natove trans unit status "initial", testcase for issue #57', function (done) { | ||
it('should generate translated file for all languages with set praefix and suffix (#70)', function (done) { | ||
file_util_1.FileUtil.copy(MASTER1SRC, MASTER); | ||
@@ -181,2 +181,46 @@ var ws = new writer_to_string_1.WriterToString(); | ||
i18nFile: MASTERFILE, | ||
targetPraefix: '%%', | ||
targetSuffix: '!!', | ||
} | ||
}; | ||
var xliffMergeCmd = xliff_merge_1.XliffMerge.createFromOptions(commandOut, { languages: ['de', 'en'] }, profileContent); | ||
xliffMergeCmd.run(); | ||
expect(ws.writtenData()).not.toContain('ERROR'); | ||
var langFileGerman = readXliff2(xliffMergeCmd.generatedI18nFile('de')); | ||
expect(langFileGerman.sourceLanguage()).toBe('de'); | ||
expect(langFileGerman.targetLanguage()).toBe('de'); | ||
langFileGerman.forEachTransUnit(function (tu) { | ||
if (!tu.targetContent().startsWith('{VAR')) { | ||
expect(tu.targetContent()).toBe('%%' + tu.sourceContent() + '!!'); | ||
} | ||
else { | ||
expect(tu.targetContent()).toBe(tu.sourceContent()); | ||
} | ||
expect(tu.targetState()).toBe('final'); | ||
}); | ||
var langFileEnglish = readXliff2(xliffMergeCmd.generatedI18nFile('en')); | ||
expect(langFileEnglish.sourceLanguage()).toBe('de'); | ||
expect(langFileEnglish.targetLanguage()).toBe('en'); | ||
langFileEnglish.forEachTransUnit(function (tu) { | ||
if (!tu.targetContent().startsWith('{VAR')) { | ||
expect(tu.targetContent()).toBe('%%' + tu.sourceContent() + '!!'); | ||
} | ||
else { | ||
expect(tu.targetContent()).toBe(tu.sourceContent()); | ||
} | ||
expect(tu.targetState()).toBe('new'); | ||
}); | ||
done(); | ||
}); | ||
it('should generate translated file with native trans unit status "initial", testcase for issue #57', function (done) { | ||
file_util_1.FileUtil.copy(MASTER1SRC, MASTER); | ||
var ws = new writer_to_string_1.WriterToString(); | ||
var commandOut = new command_output_1.CommandOutput(ws); | ||
var profileContent = { | ||
xliffmergeOptions: { | ||
defaultLanguage: 'de', | ||
srcDir: WORKDIR, | ||
genDir: WORKDIR, | ||
i18nFormat: 'xlf2', | ||
i18nFile: MASTERFILE, | ||
useSourceAsTarget: false | ||
@@ -183,0 +227,0 @@ } |
@@ -133,2 +133,8 @@ "use strict"; | ||
} | ||
if (!util_1.isNullOrUndefined(profile.targetPraefix)) { | ||
this._targetPraefix = profile.targetPraefix; | ||
} | ||
if (!util_1.isNullOrUndefined(profile.targetSuffix)) { | ||
this._targetSuffix = profile.targetSuffix; | ||
} | ||
if (!util_1.isNullOrUndefined(profile.autotranslate)) { | ||
@@ -214,2 +220,11 @@ this._autotranslate = profile.autotranslate; | ||
} | ||
// targetPraefix and targetSuffix check | ||
if (!this.useSourceAsTarget()) { | ||
if (this.targetPraefix().length > 0) { | ||
this.warningsFound.push('configured targetPraefix "' + this.targetPraefix() + '" will not be used because "useSourceAsTarget" is disabled"'); | ||
} | ||
if (this.targetSuffix().length > 0) { | ||
this.warningsFound.push('configured targetSuffix "' + this.targetSuffix() + '" will not be used because "useSourceAsTarget" is disabled"'); | ||
} | ||
} | ||
}; | ||
@@ -253,2 +268,6 @@ /** | ||
commandOutput.debug('useSourceAsTarget:\t%s', this.useSourceAsTarget()); | ||
if (this.useSourceAsTarget()) { | ||
commandOutput.debug('targetPraefix:\t"%s"', this.targetPraefix()); | ||
commandOutput.debug('targetSuffix:\t"%s"', this.targetSuffix()); | ||
} | ||
commandOutput.debug('allowIdChange:\t%s', this.allowIdChange()); | ||
@@ -356,2 +375,16 @@ commandOutput.debug('autotranslate:\t%s', this.autotranslate()); | ||
/** | ||
* Praefix used for target when copying new trans-units | ||
* Default is "" | ||
*/ | ||
XliffMergeParameters.prototype.targetPraefix = function () { | ||
return (util_1.isNullOrUndefined(this._targetPraefix)) ? "" : this._targetPraefix; | ||
}; | ||
/** | ||
* Suffix used for target when copying new trans-units | ||
* Default is "" | ||
*/ | ||
XliffMergeParameters.prototype.targetSuffix = function () { | ||
return (util_1.isNullOrUndefined(this._targetSuffix)) ? "" : this._targetSuffix; | ||
}; | ||
/** | ||
* Whether to use autotranslate for new trans-units | ||
@@ -358,0 +391,0 @@ * Default is false |
@@ -169,2 +169,9 @@ "use strict"; | ||
}; | ||
/** | ||
* Warnings found during the run. | ||
* @return {string[]} | ||
*/ | ||
XliffMerge.prototype.warnings = function () { | ||
return this.parameters.warningsFound; | ||
}; | ||
XliffMerge.prototype.readMaster = function () { | ||
@@ -256,2 +263,4 @@ var _this = this; | ||
var isDefaultLang = (lang == this.parameters.defaultLanguage()); | ||
this.master.setNewTransUnitTargetPraefix(this.parameters.targetPraefix()); | ||
this.master.setNewTransUnitTargetSuffix(this.parameters.targetSuffix()); | ||
var languageSpecificMessagesFile = this.master.createTranslationFileForLang(lang, languageXliffFilePath, isDefaultLang, this.parameters.useSourceAsTarget()); | ||
@@ -296,2 +305,4 @@ return this.autoTranslate(this.master.sourceLanguage(), lang, languageSpecificMessagesFile).map(function (summary) { | ||
var idChangedCount = 0; | ||
languageSpecificMessagesFile.setNewTransUnitTargetPraefix(this.parameters.targetPraefix()); | ||
languageSpecificMessagesFile.setNewTransUnitTargetSuffix(this.parameters.targetSuffix()); | ||
this.master.forEachTransUnit(function (masterTransUnit) { | ||
@@ -298,0 +309,0 @@ var transUnit = languageSpecificMessagesFile.transUnitWithId(masterTransUnit.id); |
@@ -372,4 +372,38 @@ "use strict"; | ||
}); | ||
it('should accept targetPraefix and targetSuffix parameter', function (done) { | ||
var ws = new writer_to_string_1.WriterToString(); | ||
var commandOut = new command_output_1.CommandOutput(ws); | ||
var profileContent = { | ||
xliffmergeOptions: { | ||
languages: ['de', 'en', 'fr'], | ||
targetPraefix: '%%', | ||
targetSuffix: '!!', | ||
} | ||
}; | ||
var xliffMergeCmd = xliff_merge_1.XliffMerge.createFromOptions(commandOut, { verbose: true }, profileContent); | ||
xliffMergeCmd.run(); | ||
expect(ws.writtenData()).toContain('* targetPraefix:\t"%%"'); | ||
expect(ws.writtenData()).toContain('* targetSuffix:\t"!!"'); | ||
done(); | ||
}); | ||
it('should output a warning when targetPraefix or targetSuffix are set, but useSourceAsTarget is disabled', function (done) { | ||
var ws = new writer_to_string_1.WriterToString(); | ||
var commandOut = new command_output_1.CommandOutput(ws); | ||
var profileContent = { | ||
xliffmergeOptions: { | ||
languages: ["de"], | ||
useSourceAsTarget: false, | ||
targetPraefix: '%%', | ||
targetSuffix: '!!', | ||
} | ||
}; | ||
var xliffMergeCmd = xliff_merge_1.XliffMerge.createFromOptions(commandOut, { verbose: true }, profileContent); | ||
xliffMergeCmd.run(); | ||
var allWarnings = xliffMergeCmd.warnings().join('\n'); | ||
expect(allWarnings).toContain('configured targetPraefix "%%" will not be used because "useSourceAsTarget" is disabled'); | ||
expect(allWarnings).toContain('configured targetSuffix "!!" will not be used because "useSourceAsTarget" is disabled'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=S:/experimente/ngx-i18nsupport/xliffmerge/xliff-merge.spec.js.map |
@@ -109,2 +109,40 @@ "use strict"; | ||
}); | ||
it('should generate translated file for all languages with set praefix and suffix (#70)', function (done) { | ||
file_util_1.FileUtil.copy(MASTER1SRC, MASTER); | ||
var ws = new writer_to_string_1.WriterToString(); | ||
var commandOut = new command_output_1.CommandOutput(ws); | ||
var profileContent = { | ||
xliffmergeOptions: { | ||
defaultLanguage: 'de', | ||
srcDir: WORKDIR, | ||
genDir: WORKDIR, | ||
i18nFormat: 'xmb', | ||
i18nFile: MASTERFILE, | ||
targetPraefix: '%%', | ||
targetSuffix: '!!', | ||
} | ||
}; | ||
var xliffMergeCmd = xliff_merge_1.XliffMerge.createFromOptions(commandOut, { languages: ['de', 'en'] }, profileContent); | ||
xliffMergeCmd.run(); | ||
expect(ws.writtenData()).not.toContain('ERROR'); | ||
var langFileGerman = readXtbWithMaster(xliffMergeCmd.generatedI18nFile('de'), MASTER); | ||
langFileGerman.forEachTransUnit(function (tu) { | ||
if (!tu.targetContent().startsWith('{VAR')) { | ||
expect(tu.targetContent()).toBe('%%' + tu.sourceContent() + '!!'); | ||
} | ||
else { | ||
expect(tu.targetContent()).toBe(tu.sourceContent()); | ||
} | ||
}); | ||
var langFileEnglish = readXtbWithMaster(xliffMergeCmd.generatedI18nFile('en'), MASTER); | ||
langFileEnglish.forEachTransUnit(function (tu) { | ||
if (!tu.targetContent().startsWith('{VAR')) { | ||
expect(tu.targetContent()).toBe('%%' + tu.sourceContent() + '!!'); | ||
} | ||
else { | ||
expect(tu.targetContent()).toBe(tu.sourceContent()); | ||
} | ||
}); | ||
done(); | ||
}); | ||
it('should merge translated file for all languages using format xmb', function (done) { | ||
@@ -111,0 +149,0 @@ file_util_1.FileUtil.copy(MASTER1SRC, MASTER); |
{ | ||
"name": "ngx-i18nsupport", | ||
"version": "0.11.1", | ||
"version": "0.12.0", | ||
"description": "Some tooling to be used with the Angular 2 i18n workflow", | ||
@@ -54,3 +54,3 @@ "main": "index.js", | ||
"commander": "^2.9.0", | ||
"ngx-i18nsupport-lib": "^1.7.0", | ||
"ngx-i18nsupport-lib": "^1.8.1", | ||
"request": "^2.81.0", | ||
@@ -57,0 +57,0 @@ "rxjs": "^5.5.6" |
@@ -98,2 +98,4 @@ [![Build Status][travis-badge]][travis-badge-url] | ||
"useSourceAsTarget": true, | ||
"targetPraefix": "", | ||
"targetSuffix": "", | ||
"allowIdChange": false, | ||
@@ -123,3 +125,11 @@ "autotranslate": false, | ||
- `useSourceAsTarget` (boolean, default `true`): flag, if source should be copied to target for new trans-units | ||
- `allowIdChange` (boolean, default `false`): | ||
- `targetPraefix` (since 0.12.0) (string, default """): | ||
when the flag `useSourceAsTarget` is set and a source is copied to target, | ||
then the target string will be praefixed by this value. | ||
E.g. `targetPraefix: "%%"` and source contains the string "menu", target will contain "%%menu" at the end. | ||
- `targetSuffix` (since 0.12.0) (string, default """): | ||
when the flag `useSourceAsTarget` is set and a source is copied to target, | ||
then the target string will be suffixed by this value. | ||
E.g. `targetSuffix: "%%"` and source contains the string "menu", target will contain "menu%%" at the end. | ||
- `allowIdChange` (since 0.11.0) (boolean, default `false`): | ||
flag, wether xliffmerge should merge transunits with changed IDs. | ||
@@ -126,0 +136,0 @@ When there is only a small change in the original message text, e.g. a trailing white space, the Angular extraction tool will change the ID of the unit. |
@@ -43,2 +43,4 @@ /** | ||
useSourceAsTarget?: boolean; // Flag, whether source must be used as target for new trans-units | ||
targetPraefix?: string; // Praefix for target copied from sourced | ||
targetSuffix?: string; // Suffix for target copied from sourced | ||
autotranslate?: boolean|string[]; // enable auto translate via Google Translate | ||
@@ -45,0 +47,0 @@ // if it is an array, list of languages to autotranslate |
@@ -108,3 +108,3 @@ import * as fs from "fs"; | ||
i18nFile: MASTERFILE, | ||
useSourceAsTarget: false | ||
useSourceAsTarget: false | ||
} | ||
@@ -167,3 +167,3 @@ }; | ||
i18nFile: MASTERFILE, | ||
useSourceAsTarget: false | ||
useSourceAsTarget: false | ||
} | ||
@@ -191,2 +191,44 @@ }; | ||
it('should generate translated file for all languages with set praefix and suffix (#70)', (done) => { | ||
FileUtil.copy(MASTER1SRC, MASTER); | ||
let ws: WriterToString = new WriterToString(); | ||
let commandOut = new CommandOutput(ws); | ||
let profileContent: IConfigFile = { | ||
xliffmergeOptions: { | ||
defaultLanguage: 'de', | ||
srcDir: WORKDIR, | ||
genDir: WORKDIR, | ||
i18nFile: MASTERFILE, | ||
targetPraefix: '%%', | ||
targetSuffix: '!!', | ||
} | ||
}; | ||
let xliffMergeCmd = XliffMerge.createFromOptions(commandOut, {languages: ['de', 'en']}, profileContent); | ||
xliffMergeCmd.run(); | ||
expect(ws.writtenData()).not.toContain('ERROR'); | ||
let langFileGerman: ITranslationMessagesFile = readXliff(xliffMergeCmd.generatedI18nFile('de')); | ||
expect(langFileGerman.sourceLanguage()).toBe('de'); | ||
expect(langFileGerman.targetLanguage()).toBe('de'); | ||
langFileGerman.forEachTransUnit((tu: ITransUnit) => { | ||
if (!tu.targetContent().startsWith('{VAR')) { | ||
expect(tu.targetContent()).toBe('%%' + tu.sourceContent() + '!!'); | ||
} else { | ||
expect(tu.targetContent()).toBe(tu.sourceContent()); | ||
} | ||
expect(tu.targetState()).toBe('final'); | ||
}); | ||
let langFileEnglish: ITranslationMessagesFile = readXliff(xliffMergeCmd.generatedI18nFile('en')); | ||
expect(langFileEnglish.sourceLanguage()).toBe('de'); | ||
expect(langFileEnglish.targetLanguage()).toBe('en'); | ||
langFileEnglish.forEachTransUnit((tu: ITransUnit) => { | ||
if (!tu.targetContent().startsWith('{VAR')) { | ||
expect(tu.targetContent()).toBe('%%' + tu.sourceContent() + '!!'); | ||
} else { | ||
expect(tu.targetContent()).toBe(tu.sourceContent()); | ||
} | ||
expect(tu.targetState()).toBe('new'); | ||
}); | ||
done(); | ||
}); | ||
it('should merge translated file for all languages', (done) => { | ||
@@ -193,0 +235,0 @@ FileUtil.copy(MASTER1SRC, MASTER); |
@@ -183,3 +183,3 @@ import * as fs from "fs"; | ||
it('should generate translated file with natove trans unit status "initial", testcase for issue #57', (done) => { | ||
it('should generate translated file for all languages with set praefix and suffix (#70)', (done) => { | ||
FileUtil.copy(MASTER1SRC, MASTER); | ||
@@ -195,2 +195,45 @@ let ws: WriterToString = new WriterToString(); | ||
i18nFile: MASTERFILE, | ||
targetPraefix: '%%', | ||
targetSuffix: '!!', | ||
} | ||
}; | ||
let xliffMergeCmd = XliffMerge.createFromOptions(commandOut, {languages: ['de', 'en']}, profileContent); | ||
xliffMergeCmd.run(); | ||
expect(ws.writtenData()).not.toContain('ERROR'); | ||
let langFileGerman: ITranslationMessagesFile = readXliff2(xliffMergeCmd.generatedI18nFile('de')); | ||
expect(langFileGerman.sourceLanguage()).toBe('de'); | ||
expect(langFileGerman.targetLanguage()).toBe('de'); | ||
langFileGerman.forEachTransUnit((tu: ITransUnit) => { | ||
if (!tu.targetContent().startsWith('{VAR')) { | ||
expect(tu.targetContent()).toBe('%%' + tu.sourceContent() + '!!'); | ||
} else { | ||
expect(tu.targetContent()).toBe(tu.sourceContent()); | ||
} | ||
expect(tu.targetState()).toBe('final'); | ||
}); | ||
let langFileEnglish: ITranslationMessagesFile = readXliff2(xliffMergeCmd.generatedI18nFile('en')); | ||
expect(langFileEnglish.sourceLanguage()).toBe('de'); | ||
expect(langFileEnglish.targetLanguage()).toBe('en'); | ||
langFileEnglish.forEachTransUnit((tu: ITransUnit) => { | ||
if (!tu.targetContent().startsWith('{VAR')) { | ||
expect(tu.targetContent()).toBe('%%' + tu.sourceContent() + '!!'); | ||
} else { | ||
expect(tu.targetContent()).toBe(tu.sourceContent()); | ||
} | ||
expect(tu.targetState()).toBe('new'); | ||
}); | ||
done(); | ||
}); | ||
it('should generate translated file with native trans unit status "initial", testcase for issue #57', (done) => { | ||
FileUtil.copy(MASTER1SRC, MASTER); | ||
let ws: WriterToString = new WriterToString(); | ||
let commandOut = new CommandOutput(ws); | ||
let profileContent: IConfigFile = { | ||
xliffmergeOptions: { | ||
defaultLanguage: 'de', | ||
srcDir: WORKDIR, | ||
genDir: WORKDIR, | ||
i18nFormat: 'xlf2', | ||
i18nFile: MASTERFILE, | ||
useSourceAsTarget: false | ||
@@ -197,0 +240,0 @@ } |
@@ -32,2 +32,4 @@ /** | ||
private _useSourceAsTarget: boolean; | ||
private _targetPraefix: string; | ||
private _targetSuffix: string; | ||
private _autotranslate: boolean|string[]; | ||
@@ -162,2 +164,8 @@ private _apikey: string; | ||
} | ||
if (!isNullOrUndefined(profile.targetPraefix)) { | ||
this._targetPraefix = profile.targetPraefix; | ||
} | ||
if (!isNullOrUndefined(profile.targetSuffix)) { | ||
this._targetSuffix = profile.targetSuffix; | ||
} | ||
if (!isNullOrUndefined(profile.autotranslate)) { | ||
@@ -239,2 +247,11 @@ this._autotranslate = profile.autotranslate; | ||
} | ||
// targetPraefix and targetSuffix check | ||
if (!this.useSourceAsTarget()) { | ||
if (this.targetPraefix().length > 0) { | ||
this.warningsFound.push('configured targetPraefix "' + this.targetPraefix() + '" will not be used because "useSourceAsTarget" is disabled"'); | ||
} | ||
if (this.targetSuffix().length > 0) { | ||
this.warningsFound.push('configured targetSuffix "' + this.targetSuffix() + '" will not be used because "useSourceAsTarget" is disabled"'); | ||
} | ||
} | ||
} | ||
@@ -283,2 +300,6 @@ | ||
commandOutput.debug('useSourceAsTarget:\t%s', this.useSourceAsTarget()); | ||
if (this.useSourceAsTarget()) { | ||
commandOutput.debug('targetPraefix:\t"%s"', this.targetPraefix()); | ||
commandOutput.debug('targetSuffix:\t"%s"', this.targetSuffix()); | ||
} | ||
commandOutput.debug('allowIdChange:\t%s', this.allowIdChange()); | ||
@@ -401,2 +422,18 @@ commandOutput.debug('autotranslate:\t%s', this.autotranslate()); | ||
/** | ||
* Praefix used for target when copying new trans-units | ||
* Default is "" | ||
*/ | ||
public targetPraefix(): string { | ||
return (isNullOrUndefined(this._targetPraefix)) ? "" : this._targetPraefix; | ||
} | ||
/** | ||
* Suffix used for target when copying new trans-units | ||
* Default is "" | ||
*/ | ||
public targetSuffix(): string { | ||
return (isNullOrUndefined(this._targetSuffix)) ? "" : this._targetSuffix; | ||
} | ||
/** | ||
* Whether to use autotranslate for new trans-units | ||
@@ -403,0 +440,0 @@ * Default is false |
@@ -404,4 +404,40 @@ import {XliffMerge} from './xliff-merge'; | ||
it('should accept targetPraefix and targetSuffix parameter', (done) => { | ||
let ws: WriterToString = new WriterToString(); | ||
let commandOut = new CommandOutput(ws); | ||
let profileContent: IConfigFile = { | ||
xliffmergeOptions: { | ||
languages: ['de', 'en', 'fr'], | ||
targetPraefix: '%%', | ||
targetSuffix: '!!', | ||
} | ||
}; | ||
let xliffMergeCmd = XliffMerge.createFromOptions(commandOut, {verbose: true}, profileContent); | ||
xliffMergeCmd.run(); | ||
expect(ws.writtenData()).toContain('* targetPraefix:\t"%%"'); | ||
expect(ws.writtenData()).toContain('* targetSuffix:\t"!!"'); | ||
done(); | ||
}); | ||
it('should output a warning when targetPraefix or targetSuffix are set, but useSourceAsTarget is disabled', (done) => { | ||
let ws: WriterToString = new WriterToString(); | ||
let commandOut = new CommandOutput(ws); | ||
let profileContent: IConfigFile = { | ||
xliffmergeOptions: { | ||
languages: ["de"], | ||
useSourceAsTarget: false, | ||
targetPraefix: '%%', | ||
targetSuffix: '!!', | ||
} | ||
}; | ||
let xliffMergeCmd = XliffMerge.createFromOptions(commandOut, {verbose: true}, profileContent); | ||
xliffMergeCmd.run(); | ||
const allWarnings = xliffMergeCmd.warnings().join('\n'); | ||
expect(allWarnings).toContain('configured targetPraefix "%%" will not be used because "useSourceAsTarget" is disabled'); | ||
expect(allWarnings).toContain('configured targetSuffix "!!" will not be used because "useSourceAsTarget" is disabled'); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -192,2 +192,10 @@ import * as program from 'commander'; | ||
/** | ||
* Warnings found during the run. | ||
* @return {string[]} | ||
*/ | ||
public warnings(): string[] { | ||
return this.parameters.warningsFound; | ||
} | ||
private readMaster() { | ||
@@ -274,2 +282,4 @@ try { | ||
let isDefaultLang: boolean = (lang == this.parameters.defaultLanguage()); | ||
this.master.setNewTransUnitTargetPraefix(this.parameters.targetPraefix()); | ||
this.master.setNewTransUnitTargetSuffix(this.parameters.targetSuffix()); | ||
let languageSpecificMessagesFile: ITranslationMessagesFile = this.master.createTranslationFileForLang(lang, languageXliffFilePath, isDefaultLang, this.parameters.useSourceAsTarget()); | ||
@@ -308,3 +318,2 @@ return this.autoTranslate(this.master.sourceLanguage(), lang, languageSpecificMessagesFile).map((summary) => { | ||
let languageSpecificMessagesFile: ITranslationMessagesFile = TranslationMessagesFileReader.fromFile(XliffMerge.translationFormat(this.parameters.i18nFormat()), languageXliffFilePath, this.parameters.encoding()); | ||
let isDefaultLang: boolean = (lang == this.parameters.defaultLanguage()); | ||
@@ -316,2 +325,4 @@ let newCount = 0; | ||
let idChangedCount = 0; | ||
languageSpecificMessagesFile.setNewTransUnitTargetPraefix(this.parameters.targetPraefix()); | ||
languageSpecificMessagesFile.setNewTransUnitTargetSuffix(this.parameters.targetSuffix()); | ||
this.master.forEachTransUnit((masterTransUnit) => { | ||
@@ -318,0 +329,0 @@ let transUnit: ITransUnit = languageSpecificMessagesFile.transUnitWithId(masterTransUnit.id); |
@@ -122,2 +122,39 @@ import * as fs from "fs"; | ||
it('should generate translated file for all languages with set praefix and suffix (#70)', (done) => { | ||
FileUtil.copy(MASTER1SRC, MASTER); | ||
let ws: WriterToString = new WriterToString(); | ||
let commandOut = new CommandOutput(ws); | ||
let profileContent: IConfigFile = { | ||
xliffmergeOptions: { | ||
defaultLanguage: 'de', | ||
srcDir: WORKDIR, | ||
genDir: WORKDIR, | ||
i18nFormat: 'xmb', | ||
i18nFile: MASTERFILE, | ||
targetPraefix: '%%', | ||
targetSuffix: '!!', | ||
} | ||
}; | ||
let xliffMergeCmd = XliffMerge.createFromOptions(commandOut, {languages: ['de', 'en']}, profileContent); | ||
xliffMergeCmd.run(); | ||
expect(ws.writtenData()).not.toContain('ERROR'); | ||
let langFileGerman: ITranslationMessagesFile = readXtbWithMaster(xliffMergeCmd.generatedI18nFile('de'), MASTER); | ||
langFileGerman.forEachTransUnit((tu: ITransUnit) => { | ||
if (!tu.targetContent().startsWith('{VAR')) { | ||
expect(tu.targetContent()).toBe('%%' + tu.sourceContent() + '!!'); | ||
} else { | ||
expect(tu.targetContent()).toBe(tu.sourceContent()); | ||
} | ||
}); | ||
let langFileEnglish: ITranslationMessagesFile = readXtbWithMaster(xliffMergeCmd.generatedI18nFile('en'), MASTER); | ||
langFileEnglish.forEachTransUnit((tu: ITransUnit) => { | ||
if (!tu.targetContent().startsWith('{VAR')) { | ||
expect(tu.targetContent()).toBe('%%' + tu.sourceContent() + '!!'); | ||
} else { | ||
expect(tu.targetContent()).toBe(tu.sourceContent()); | ||
} | ||
}); | ||
done(); | ||
}); | ||
it('should merge translated file for all languages using format xmb', (done) => { | ||
@@ -124,0 +161,0 @@ FileUtil.copy(MASTER1SRC, MASTER); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
753410
9222
249
Updatedngx-i18nsupport-lib@^1.8.1