Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds flag for compressed output. #17

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const options = new Command()
.option('--no-reset-translation-state', 'prevent (re-)setting the translation state to new/initial for new/changed units')
.option('--no-replace-apostrophe', 'prevent replacing of apostrophes (\') with "'"')
.option('-w, --overwrite-with-translated', 'overwrite target of destination with target of source, if it\'s translated and destination target not')
.option('-c, --compress-output', 'enables xmldoc compression for stripping indents and linebreaks in output.')
.option('--debug', 'enable debug output')
.parse()
.opts();
Expand All @@ -32,6 +33,7 @@ const outString = merge(inFilesContent, destFileContent, {
resetTranslationState: options.resetTranslationState,
replaceApostrophe: options.replaceApostrophe,
overwriteTargetWithTranslated: options.overwriteWithTranslated,
compressOutput: options.compressOutput,
}, options.destinationFile);

fs.writeFileSync(options.outputFile ?? options.destinationFile, outString, {encoding: 'utf8'});
fs.writeFileSync(options.outputFile ?? options.destinationFile, outString, {encoding: 'utf8'});
3 changes: 2 additions & 1 deletion src/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type MergeOptions = {
/** For untranslated units with initial state (state="initial" / state="new"), an updated source will be copied into the target (unless `newTranslationTargetsBlank='omit'/true`) */
syncTargetsWithInitialState?: boolean,
overwriteTargetWithTranslated?: boolean,
compressOutput?: boolean
};

const FUZZY_THRESHOLD = 0.2;
Expand Down Expand Up @@ -312,7 +313,7 @@ export function mergeWithMapping(inFilesContent: string | string[], destFileCont

const mergedContent = xmlDeclaration + revertApostrophes(destDoc.toString({
preserveWhitespace: true,
compressed: false
compressed: options?.compressOutput == true
}), !options?.replaceApostrophe).replace(/^\s*[\r\n]/gm, '');

return [mergedContent, idMapping];
Expand Down
Loading