use of org.omegat.CLIParameters.PSEUDO_TRANSLATE_TYPE in project omegat by omegat-org.
the class Main method runCreatePseudoTranslateTMX.
/**
* Execute in console mode for translate.
*/
protected static int runCreatePseudoTranslateTMX() throws Exception {
Log.log("Console pseudo-translate mode");
Log.log("");
System.out.println(OStrings.getString("CONSOLE_INITIALIZING"));
Core.initializeConsole(PARAMS);
RealProject p = selectProjectConsoleMode(true);
validateTagsConsoleMode();
System.out.println(OStrings.getString("CONSOLE_CREATE_PSEUDOTMX"));
ProjectProperties config = p.getProjectProperties();
List<SourceTextEntry> entries = p.getAllEntries();
String pseudoTranslateTMXFilename = PARAMS.get(CLIParameters.PSEUDOTRANSLATETMX);
PSEUDO_TRANSLATE_TYPE pseudoTranslateType = PSEUDO_TRANSLATE_TYPE.parse(PARAMS.get(CLIParameters.PSEUDOTRANSLATETYPE));
String fname;
if (!StringUtil.isEmpty(pseudoTranslateTMXFilename)) {
if (!pseudoTranslateTMXFilename.endsWith(OConsts.TMX_EXTENSION)) {
fname = pseudoTranslateTMXFilename + "." + OConsts.TMX_EXTENSION;
} else {
fname = pseudoTranslateTMXFilename;
}
} else {
fname = "";
}
// prepare tmx
Map<String, PrepareTMXEntry> data = new HashMap<>();
for (SourceTextEntry ste : entries) {
PrepareTMXEntry entry = new PrepareTMXEntry();
entry.source = ste.getSrcText();
switch(pseudoTranslateType) {
case EQUAL:
entry.translation = ste.getSrcText();
break;
case EMPTY:
entry.translation = "";
break;
}
data.put(ste.getSrcText(), entry);
}
try {
// Write OmegaT-project-compatible TMX:
TMXWriter.buildTMXFile(fname, false, false, config, data);
} catch (IOException e) {
Log.logErrorRB("CT_ERROR_CREATING_TMX");
Log.log(e);
throw new IOException(OStrings.getString("CT_ERROR_CREATING_TMX") + "\n" + e.getMessage());
}
p.closeProject();
System.out.println(OStrings.getString("CONSOLE_FINISHED"));
return 0;
}
Aggregations