Skip to content

Commit

Permalink
Merge pull request #65 from Szpadel/master
Browse files Browse the repository at this point in the history
Add new option "allowIdChange"
  • Loading branch information
martinroob committed Feb 2, 2018
2 parents 7df15f3 + ab16d1e commit 4376650
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/xliffmerge/i-xliff-merge-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface IConfigFile {
export interface IXliffMergeOptions {
quiet?: boolean; // Flag to only output error messages
verbose?: boolean; // Flag to generate debug output messages
allowIdChange?: boolean; // Try to find translation even when id is missing
defaultLanguage?: string; // the default language (the language, which is used in the original templates)
languages?: string[]; // all languages, if not specified via commandline
srcDir?: string; // Directory, where the master file is
Expand Down
8 changes: 8 additions & 0 deletions src/xliffmerge/xliff-merge-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class XliffMergeParameters {

private _quiet: boolean;
private _verbose: boolean;
private _allowIdChange: boolean;
private _defaultLanguage: string;
private _srcDir: string;
private _i18nFile: string;
Expand Down Expand Up @@ -116,6 +117,9 @@ export class XliffMergeParameters {
if (!isNullOrUndefined(profile.verbose)) {
this._verbose = profile.verbose;
}
if(!isNullOrUndefined(profile.allowIdChange)) {
this._allowIdChange = profile.allowIdChange;
}
if (profile.defaultLanguage) {
this._defaultLanguage = profile.defaultLanguage;
}
Expand Down Expand Up @@ -245,6 +249,10 @@ export class XliffMergeParameters {
}
}

public allowIdChange(): boolean {
return (isNullOrUndefined(this._allowIdChange)) ? false : this._allowIdChange;
}

public verbose(): boolean {
return (isNullOrUndefined(this._verbose)) ? false : this._verbose;
}
Expand Down
17 changes: 16 additions & 1 deletion src/xliffmerge/xliff-merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import {XliffMergeAutoTranslateService} from '../autotranslate/xliff-merge-auto-translate-service';
import {AutoTranslateSummaryReport} from '../autotranslate/auto-translate-summary-report';
import {STATE_FINAL, STATE_TRANSLATED} from 'ngx-i18nsupport-lib/dist';
import {NORMALIZATION_FORMAT_DEFAULT, STATE_FINAL, STATE_NEW, STATE_TRANSLATED} from 'ngx-i18nsupport-lib/dist';

/**
* Created by martin on 17.02.2017.
Expand Down Expand Up @@ -309,8 +309,20 @@ export class XliffMerge {
let correctSourceContentCount = 0;
let correctSourceRefCount = 0;
let correctDescriptionOrMeaningCount = 0;
let idChangedCount = 0;
this.master.forEachTransUnit((masterTransUnit) => {
let transUnit: ITransUnit = languageSpecificMessagesFile.transUnitWithId(masterTransUnit.id);
if(!transUnit && this.parameters.allowIdChange()) {
const masterSourceString = masterTransUnit.sourceContentNormalized().asDisplayString(NORMALIZATION_FORMAT_DEFAULT).trim();
languageSpecificMessagesFile.forEachTransUnit((languageTransUnit) => {
if(languageTransUnit.sourceContentNormalized().asDisplayString(NORMALIZATION_FORMAT_DEFAULT).trim() === masterSourceString) {
transUnit = languageTransUnit;
languageTransUnit.setTargetState(STATE_TRANSLATED);
idChangedCount++;
}
})
}

if (!transUnit) {
// oops, no translation, must be a new key, so add it
languageSpecificMessagesFile.importNewTransUnit(masterTransUnit, isDefaultLang, this.parameters.useSourceAsTarget());
Expand Down Expand Up @@ -357,6 +369,9 @@ export class XliffMerge {
if (correctSourceRefCount > 0) {
this.commandOutput.warn('transferred %s source references from master to "%s"', correctSourceRefCount, lang);
}
if(idChangedCount > 0) {
this.commandOutput.warn('found %s changed id\'s in "%s"', idChangedCount, lang);
}
if (correctDescriptionOrMeaningCount > 0) {
this.commandOutput.warn('transferred %s changed descriptions/meanings from master to "%s"', correctDescriptionOrMeaningCount, lang);
}
Expand Down

0 comments on commit 4376650

Please sign in to comment.