(feat) add argument --null-as-default-value to use null as default value for extracted translations

This commit is contained in:
Kim Biesbjerg
2019-09-16 17:52:41 +02:00
parent eb7f3f603e
commit 97e8937709
5 changed files with 71 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ import { MarkerParser } from '../parsers/marker.parser';
import { PostProcessorInterface } from '../post-processors/post-processor.interface';
import { SortByKeyPostProcessor } from '../post-processors/sort-by-key.post-processor';
import { KeyAsDefaultValuePostProcessor } from '../post-processors/key-as-default-value.post-processor';
import { NullAsDefaultValuePostProcessor } from '../post-processors/null-as-default-value.post-processor';
import { PurgeObsoleteKeysPostProcessor } from '../post-processors/purge-obsolete-keys.post-processor';
import { CompilerInterface } from '../compilers/compiler.interface';
import { CompilerFactory } from '../compilers/compiler.factory';
@@ -87,6 +88,13 @@ export const cli = yargs
default: false,
type: 'boolean'
})
.option('null-as-default-value', {
alias: 'n',
describe: 'Use null as default value for translations',
default: false,
type: 'boolean'
})
.conflicts('key-as-default-value', 'null-as-default-value')
.exitProcess(true)
.parse(process.argv);
@@ -111,6 +119,8 @@ if (cli.clean) {
}
if (cli.keyAsDefaultValue) {
postProcessors.push(new KeyAsDefaultValuePostProcessor());
} else if (cli.nullAsDefaultValue) {
postProcessors.push(new NullAsDefaultValuePostProcessor());
}
if (cli.sort) {
postProcessors.push(new SortByKeyPostProcessor());

View File

@@ -0,0 +1,12 @@
import { TranslationCollection } from '../utils/translation.collection';
import { PostProcessorInterface } from './post-processor.interface';
export class NullAsDefaultValuePostProcessor implements PostProcessorInterface {
public name: string = 'NullAsDefaultValue';
public process(draft: TranslationCollection, extracted: TranslationCollection, existing: TranslationCollection): TranslationCollection {
return draft.map((key, val) => existing.get(key) === undefined ? null : val);
}
}