Skip to content

Commit

Permalink
feat(diff-handler): show master file values in diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdel El-Medny committed Feb 5, 2019
1 parent a84f94c commit 056cc17
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ export class Main {
this.analyzer.logDifferences(differences, configuration!.autoFix);

if ( configuration!.autoFix ) {
const fixedFilesMap = this.translationsDifferenceHandler.handle(translationsMap!, differences);
const fixedFilesMap = this.translationsDifferenceHandler.handle(
translationsMap!,
differences,
configuration!.masterFileName
);

this.translationWriter.write(
fixedFilesMap,
Expand Down
9 changes: 5 additions & 4 deletions src/translation-difference-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ import { ITranslationFile, ITranslationDifference } from "../types";

export class TranslationsDifferenceHandler {

handle(originalFiles: Map<string, ITranslationFile>, differencesMap: Map<string, ITranslationDifference>): Map<string, ITranslationFile> {
handle(originalFiles: Map<string, ITranslationFile>, differencesMap: Map<string, ITranslationDifference>, masterFileName: string): Map<string, ITranslationFile> {
const newFiles = new Map<string, ITranslationFile>(originalFiles);

const masterFileTranslations = originalFiles.get(masterFileName)!;

for (const [fileName, value] of differencesMap.entries()) {
if (differencesMap.get(fileName)!.missing.length || differencesMap.get(fileName)!.redundant.length) {
const newFileValue = newFiles.get(fileName)!;
if (differencesMap.get(fileName)!.redundant.length) {
differencesMap.get(fileName)!.redundant.forEach(redundantKey => {
delete newFileValue[redundantKey];
});

}

if (differencesMap.get(fileName)!.missing.length) {
differencesMap.get(fileName)!.missing.forEach(missingKey => {
newFileValue[missingKey] = `⚠️ Missing`;
differencesMap.get(fileName)!.missing.forEach(missingKey => {
newFileValue[missingKey] = `⚠️ ${masterFileTranslations![missingKey]}`;
});
}
newFiles.set(fileName, newFileValue);
Expand Down

0 comments on commit 056cc17

Please sign in to comment.