Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngx-i18nsupport

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-i18nsupport - npm Package Compare versions

Comparing version 0.16.3 to 0.17.0

test/testdata/i18n/issue97emptylines.ru.xlf

15

Changelog.md

@@ -0,1 +1,16 @@

<a name="0.17.0"></a>
# [0.17.0](https://github.com/martinroob/ngx-i18nsupport/compare/v0.16.4...v0.17.0) (2018-08-07)
### Bug fixes
* **xliffmerge** wrong empty lines were added when using beautifier.
([#96](https://github.com/martinroob/ngx-i18nsupport/issues/96)).
The beautifier is totally changed, so this might result in slightly changed outputs.
### Features
* **xliffmerge** Preserve order for newly added units.
([#96](https://github.com/martinroob/ngx-i18nsupport/issues/96)).
When merging new units from master to translation file the new units are now inserted at the same position as they were in the master.
<a name="0.16.3"></a>

@@ -2,0 +17,0 @@ # [0.16.3](https://github.com/martinroob/ngx-i18nsupport/compare/v0.16.3...v0.16.2) (2018-07-12)

@@ -382,2 +382,35 @@ "use strict";

});
it('should preserve order when merging new units (#96)', function (done) {
file_util_1.FileUtil.copy(SRCDIR + 'preserveOrderMaster1.xlf2', MASTER);
var ws = new writer_to_string_1.WriterToString();
var commandOut = new command_output_1.CommandOutput(ws);
var profileContent = {
xliffmergeOptions: {
defaultLanguage: 'en',
srcDir: WORKDIR,
genDir: WORKDIR,
i18nFormat: 'xlf2',
i18nFile: MASTERFILE
}
};
var xliffMergeCmd = xliff_merge_1.XliffMerge.createFromOptions(commandOut, { languages: ['en', 'de'] }, profileContent);
xliffMergeCmd.run();
expect(ws.writtenData()).not.toContain('ERROR');
// next step, use new master that has added 3 units
file_util_1.FileUtil.copy(SRCDIR + 'preserveOrderMaster2.xlf2', MASTER);
ws = new writer_to_string_1.WriterToString();
commandOut = new command_output_1.CommandOutput(ws);
xliffMergeCmd = xliff_merge_1.XliffMerge.createFromOptions(commandOut, { languages: ['en', 'de'] }, profileContent);
xliffMergeCmd.run();
expect(ws.writtenData()).not.toContain('ERROR');
expect(ws.writtenData()).toContain('merged 3 trans-units from master to "de"');
// look, that the new file contains the new units at the correct position
var langFileGerman = readXliff2(xliffMergeCmd.generatedI18nFile('de'));
var addedTu = langFileGerman.transUnitWithId('addedunit1');
expect(addedTu).toBeTruthy();
expect(addedTu.sourceContent()).toBe('added unit 1');
// check position
expect(langFileGerman.editedContent().replace(/(\r\n|\n|\r)/gm, "")).toMatch(/addedunit1.*firstunit.*addedunit2.*lastunit.*addedunit3/);
done();
});
it('should not remove trailing line break when merging', function (done) {

@@ -384,0 +417,0 @@ file_util_1.FileUtil.copy(MASTER1SRC, MASTER);

19

dist/xliffmerge/xliff-merge.js

@@ -312,2 +312,3 @@ "use strict";

languageSpecificMessagesFile.setNewTransUnitTargetSuffix(this.parameters.targetSuffix());
var lastProcessedUnit = null;
this.master.forEachTransUnit(function (masterTransUnit) {

@@ -317,7 +318,9 @@ var transUnit = languageSpecificMessagesFile.transUnitWithId(masterTransUnit.id);

// oops, no translation, must be a new key, so add it
if (_this.parameters.allowIdChange() && _this.processChangedIdUnit(masterTransUnit, languageSpecificMessagesFile)) {
var newUnit = void 0;
if (_this.parameters.allowIdChange() && (newUnit = _this.processChangedIdUnit(masterTransUnit, languageSpecificMessagesFile, lastProcessedUnit))) {
lastProcessedUnit = newUnit;
idChangedCount++;
}
else {
languageSpecificMessagesFile.importNewTransUnit(masterTransUnit, isDefaultLang, _this.parameters.useSourceAsTarget());
lastProcessedUnit = languageSpecificMessagesFile.importNewTransUnit(masterTransUnit, isDefaultLang, _this.parameters.useSourceAsTarget(), lastProcessedUnit);
newCount++;

@@ -364,2 +367,3 @@ }

}
lastProcessedUnit = transUnit;
}

@@ -422,5 +426,6 @@ });

* @param {ITranslationMessagesFile} languageSpecificMessagesFile translation file
* @return {boolean} true, if done, false if no changed unit found
* @param lastProcessedUnit Unit before the one processed here. New unit will be inserted after this one.
* @return {ITransUnit} processed unit, if done, null if no changed unit found
*/
XliffMerge.prototype.processChangedIdUnit = function (masterTransUnit, languageSpecificMessagesFile) {
XliffMerge.prototype.processChangedIdUnit = function (masterTransUnit, languageSpecificMessagesFile, lastProcessedUnit) {
var masterSourceString = masterTransUnit.sourceContentNormalized().asDisplayString(dist_1.NORMALIZATION_FORMAT_DEFAULT).trim();

@@ -434,5 +439,5 @@ var changedTransUnit = null;

if (!changedTransUnit) {
return false;
return null;
}
var mergedTransUnit = languageSpecificMessagesFile.importNewTransUnit(masterTransUnit, false, false);
var mergedTransUnit = languageSpecificMessagesFile.importNewTransUnit(masterTransUnit, false, false, lastProcessedUnit);
var translatedContent = changedTransUnit.targetContent();

@@ -443,3 +448,3 @@ if (translatedContent) { // issue #68 set translated only, if it is really translated

}
return true;
return mergedTransUnit;
};

@@ -446,0 +451,0 @@ XliffMerge.prototype.areSourceReferencesEqual = function (ref1, ref2) {

@@ -189,2 +189,35 @@ "use strict";

});
it('should preserve order when merging new units (#96)', function (done) {
file_util_1.FileUtil.copy(SRCDIR + 'preserveOrderMaster1.xmb', MASTER);
var ws = new writer_to_string_1.WriterToString();
var commandOut = new command_output_1.CommandOutput(ws);
var profileContent = {
xliffmergeOptions: {
defaultLanguage: 'en',
srcDir: WORKDIR,
genDir: WORKDIR,
i18nFormat: 'xmb',
i18nFile: MASTERFILE
}
};
var xliffMergeCmd = xliff_merge_1.XliffMerge.createFromOptions(commandOut, { languages: ['en', 'de'] }, profileContent);
xliffMergeCmd.run();
expect(ws.writtenData()).not.toContain('ERROR');
// next step, use new master that has added 3 units
file_util_1.FileUtil.copy(SRCDIR + 'preserveOrderMaster2.xmb', MASTER);
ws = new writer_to_string_1.WriterToString();
commandOut = new command_output_1.CommandOutput(ws);
xliffMergeCmd = xliff_merge_1.XliffMerge.createFromOptions(commandOut, { languages: ['en', 'de'] }, profileContent);
xliffMergeCmd.run();
expect(ws.writtenData()).not.toContain('ERROR');
expect(ws.writtenData()).toContain('merged 3 trans-units from master to "de"');
// look, that the new file contains the new units at the correct position
var langFileGerman = readXtbWithMaster(xliffMergeCmd.generatedI18nFile('de'));
var addedTu = langFileGerman.transUnitWithId('addedunit1');
expect(addedTu).toBeTruthy();
expect(addedTu.targetContent()).toBe('added unit 1');
// check position
expect(langFileGerman.editedContent().replace(/(\r\n|\n|\r)/gm, "")).toMatch(/addedunit1.*firstunit.*addedunit2.*lastunit.*addedunit3/);
done();
});
it('should not remove trailing line break when merging', function (done) {

@@ -191,0 +224,0 @@ file_util_1.FileUtil.copy(MASTER1SRC, MASTER);

{
"name": "ngx-i18nsupport",
"version": "0.16.3",
"version": "0.17.0",
"description": "Some tooling to be used with the Angular 2 i18n workflow",

@@ -55,3 +55,3 @@ "main": "index.js",

"he": "^1.1.1",
"ngx-i18nsupport-lib": "^1.9.2",
"ngx-i18nsupport-lib": "^1.10.0",
"request": "^2.85.0",

@@ -58,0 +58,0 @@ "rxjs": "^6.0.0"

@@ -406,2 +406,37 @@ import * as fs from "fs";

it('should preserve order when merging new units (#96)', (done) => {
FileUtil.copy(SRCDIR + 'preserveOrderMaster1.xlf', MASTER);
let ws: WriterToString = new WriterToString();
let commandOut = new CommandOutput(ws);
let profileContent: IConfigFile = {
xliffmergeOptions: {
defaultLanguage: 'en',
srcDir: WORKDIR,
genDir: WORKDIR,
i18nFile: MASTERFILE
}
};
let xliffMergeCmd = XliffMerge.createFromOptions(commandOut, {languages: ['en', 'de']}, profileContent);
xliffMergeCmd.run();
expect(ws.writtenData()).not.toContain('ERROR');
// next step, use new master that has added 3 units
FileUtil.copy(SRCDIR + 'preserveOrderMaster2.xlf', MASTER);
ws = new WriterToString();
commandOut = new CommandOutput(ws);
xliffMergeCmd = XliffMerge.createFromOptions(commandOut, {languages: ['en', 'de']}, profileContent);
xliffMergeCmd.run();
expect(ws.writtenData()).not.toContain('ERROR');
expect(ws.writtenData()).toContain('merged 3 trans-units from master to "de"');
// look, that the new file contains the new units at the correct position
const langFileGerman = readXliff(xliffMergeCmd.generatedI18nFile('de'));
const addedTu = langFileGerman.transUnitWithId('addedunit1');
expect(addedTu).toBeTruthy();
expect(addedTu.sourceContent()).toBe('added unit 1');
// check position
expect(langFileGerman.editedContent().replace(/(\r\n|\n|\r)/gm,"")).toMatch(/addedunit1.*firstunit.*addedunit2.*lastunit.*addedunit3/);
done();
});
it('should not remove trailing line break when merging', (done) => {

@@ -657,3 +692,3 @@ FileUtil.copy(MASTER1SRC, MASTER);

const formattedContent = XmlReader.readXmlFileContent(xliffMergeCmd.generatedI18nFile('en'));
expect(formattedContent.content).toContain('<xliff version="1.2" \n xmlns="urn:oasis:names:tc:xliff:document:1.2">');
expect(formattedContent.content).toContain('\n <source>Nachrichten</source>');
// to debug formatting: FileUtil.copy(xliffMergeCmd.generatedI18nFile('en'), SRCDIR + 'beautify');

@@ -663,2 +698,44 @@ done();

it('should not add empty lines when using beautify whith complex content (#97)', (done) => {
FileUtil.copy(SRCDIR + 'issue97emptylines.xlf', MASTER);
let ws: WriterToString = new WriterToString();
let commandOut = new CommandOutput(ws);
let profileContent: IConfigFile = {
xliffmergeOptions: {
defaultLanguage: 'en',
srcDir: WORKDIR,
genDir: WORKDIR,
i18nFile: MASTERFILE,
beautifyOutput: true
}
};
let xliffMergeCmd = XliffMerge.createFromOptions(commandOut, {languages: ['en', 'ru']}, profileContent);
xliffMergeCmd.run();
expect(ws.writtenData()).not.toContain('ERROR');
const formattedContent1 = XmlReader.readXmlFileContent(xliffMergeCmd.generatedI18nFile('ru'));
// to debug formatting: FileUtil.copy(xliffMergeCmd.generatedI18nFile('ru'), SRCDIR + 'beautify1');
// next step, once again with beautify
ws = new WriterToString();
commandOut = new CommandOutput(ws);
profileContent = {
xliffmergeOptions: {
defaultLanguage: 'en',
srcDir: WORKDIR,
genDir: WORKDIR,
i18nFile: MASTERFILE,
beautifyOutput: true
}
};
xliffMergeCmd = XliffMerge.createFromOptions(commandOut, {languages: ['en', 'ru']}, profileContent);
xliffMergeCmd.run();
expect(ws.writtenData()).not.toContain('ERROR');
const formattedContent2 = XmlReader.readXmlFileContent(xliffMergeCmd.generatedI18nFile('ru'));
expect(formattedContent2.content).toMatch(/I accept the\r?\n[ \t]*<x/);
expect(formattedContent2.content).not.toMatch(/I accept the\r?\n[ \t]*\r?\n[ \t]*<x/);
// to debug formatting: FileUtil.copy(xliffMergeCmd.generatedI18nFile('ru'), SRCDIR + 'beautify2');
done();
});
describe('autotranslate via google translate', () => {

@@ -665,0 +742,0 @@

@@ -407,2 +407,38 @@ import * as fs from "fs";

it('should preserve order when merging new units (#96)', (done) => {
FileUtil.copy(SRCDIR + 'preserveOrderMaster1.xlf2', MASTER);
let ws: WriterToString = new WriterToString();
let commandOut = new CommandOutput(ws);
let profileContent: IConfigFile = {
xliffmergeOptions: {
defaultLanguage: 'en',
srcDir: WORKDIR,
genDir: WORKDIR,
i18nFormat: 'xlf2',
i18nFile: MASTERFILE
}
};
let xliffMergeCmd = XliffMerge.createFromOptions(commandOut, {languages: ['en', 'de']}, profileContent);
xliffMergeCmd.run();
expect(ws.writtenData()).not.toContain('ERROR');
// next step, use new master that has added 3 units
FileUtil.copy(SRCDIR + 'preserveOrderMaster2.xlf2', MASTER);
ws = new WriterToString();
commandOut = new CommandOutput(ws);
xliffMergeCmd = XliffMerge.createFromOptions(commandOut, {languages: ['en', 'de']}, profileContent);
xliffMergeCmd.run();
expect(ws.writtenData()).not.toContain('ERROR');
expect(ws.writtenData()).toContain('merged 3 trans-units from master to "de"');
// look, that the new file contains the new units at the correct position
const langFileGerman = readXliff2(xliffMergeCmd.generatedI18nFile('de'));
const addedTu = langFileGerman.transUnitWithId('addedunit1');
expect(addedTu).toBeTruthy();
expect(addedTu.sourceContent()).toBe('added unit 1');
// check position
expect(langFileGerman.editedContent().replace(/(\r\n|\n|\r)/gm,"")).toMatch(/addedunit1.*firstunit.*addedunit2.*lastunit.*addedunit3/);
done();
});
it('should not remove trailing line break when merging', (done) => {

@@ -409,0 +445,0 @@ FileUtil.copy(MASTER1SRC, MASTER);

@@ -332,2 +332,3 @@ import * as program from 'commander';

languageSpecificMessagesFile.setNewTransUnitTargetSuffix(this.parameters.targetSuffix());
let lastProcessedUnit: ITransUnit = null;
this.master.forEachTransUnit((masterTransUnit) => {

@@ -338,6 +339,8 @@ let transUnit: ITransUnit = languageSpecificMessagesFile.transUnitWithId(masterTransUnit.id);

// oops, no translation, must be a new key, so add it
if (this.parameters.allowIdChange() && this.processChangedIdUnit(masterTransUnit, languageSpecificMessagesFile)) {
let newUnit;
if (this.parameters.allowIdChange() && (newUnit = this.processChangedIdUnit(masterTransUnit, languageSpecificMessagesFile, lastProcessedUnit))) {
lastProcessedUnit = newUnit;
idChangedCount++;
} else {
languageSpecificMessagesFile.importNewTransUnit(masterTransUnit, isDefaultLang, this.parameters.useSourceAsTarget());
lastProcessedUnit = languageSpecificMessagesFile.importNewTransUnit(masterTransUnit, isDefaultLang, this.parameters.useSourceAsTarget(), lastProcessedUnit);
newCount++;

@@ -382,2 +385,3 @@ }

}
lastProcessedUnit = transUnit;
}

@@ -441,5 +445,6 @@ });

* @param {ITranslationMessagesFile} languageSpecificMessagesFile translation file
* @return {boolean} true, if done, false if no changed unit found
* @param lastProcessedUnit Unit before the one processed here. New unit will be inserted after this one.
* @return {ITransUnit} processed unit, if done, null if no changed unit found
*/
private processChangedIdUnit(masterTransUnit: ITransUnit, languageSpecificMessagesFile: ITranslationMessagesFile): boolean {
private processChangedIdUnit(masterTransUnit: ITransUnit, languageSpecificMessagesFile: ITranslationMessagesFile, lastProcessedUnit: ITransUnit): ITransUnit {
const masterSourceString = masterTransUnit.sourceContentNormalized().asDisplayString(NORMALIZATION_FORMAT_DEFAULT).trim();

@@ -453,5 +458,5 @@ let changedTransUnit: ITransUnit = null;

if (!changedTransUnit) {
return false;
return null;
}
const mergedTransUnit = languageSpecificMessagesFile.importNewTransUnit(masterTransUnit, false, false);
const mergedTransUnit = languageSpecificMessagesFile.importNewTransUnit(masterTransUnit, false, false, lastProcessedUnit);
const translatedContent = changedTransUnit.targetContent();

@@ -462,3 +467,3 @@ if (translatedContent) { // issue #68 set translated only, if it is really translated

}
return true;
return mergedTransUnit;
}

@@ -465,0 +470,0 @@

@@ -207,2 +207,38 @@ import * as fs from "fs";

it('should preserve order when merging new units (#96)', (done) => {
FileUtil.copy(SRCDIR + 'preserveOrderMaster1.xmb', MASTER);
let ws: WriterToString = new WriterToString();
let commandOut = new CommandOutput(ws);
let profileContent: IConfigFile = {
xliffmergeOptions: {
defaultLanguage: 'en',
srcDir: WORKDIR,
genDir: WORKDIR,
i18nFormat: 'xmb',
i18nFile: MASTERFILE
}
};
let xliffMergeCmd = XliffMerge.createFromOptions(commandOut, {languages: ['en', 'de']}, profileContent);
xliffMergeCmd.run();
expect(ws.writtenData()).not.toContain('ERROR');
// next step, use new master that has added 3 units
FileUtil.copy(SRCDIR + 'preserveOrderMaster2.xmb', MASTER);
ws = new WriterToString();
commandOut = new CommandOutput(ws);
xliffMergeCmd = XliffMerge.createFromOptions(commandOut, {languages: ['en', 'de']}, profileContent);
xliffMergeCmd.run();
expect(ws.writtenData()).not.toContain('ERROR');
expect(ws.writtenData()).toContain('merged 3 trans-units from master to "de"');
// look, that the new file contains the new units at the correct position
const langFileGerman = readXtbWithMaster(xliffMergeCmd.generatedI18nFile('de'));
const addedTu = langFileGerman.transUnitWithId('addedunit1');
expect(addedTu).toBeTruthy();
expect(addedTu.targetContent()).toBe('added unit 1');
// check position
expect(langFileGerman.editedContent().replace(/(\r\n|\n|\r)/gm,"")).toMatch(/addedunit1.*firstunit.*addedunit2.*lastunit.*addedunit3/);
done();
});
it('should not remove trailing line break when merging', (done) => {

@@ -209,0 +245,0 @@ FileUtil.copy(MASTER1SRC, MASTER);

Sorry, the diff of this file is too big to display

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc