Search in sources :

Example 1 with PSEUDO_TRANSLATE_TYPE

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;
}
Also used : SourceTextEntry(org.omegat.core.data.SourceTextEntry) HashMap(java.util.HashMap) RealProject(org.omegat.core.data.RealProject) ProjectProperties(org.omegat.core.data.ProjectProperties) IOException(java.io.IOException) PSEUDO_TRANSLATE_TYPE(org.omegat.CLIParameters.PSEUDO_TRANSLATE_TYPE) PrepareTMXEntry(org.omegat.core.data.PrepareTMXEntry)

Aggregations

IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 PSEUDO_TRANSLATE_TYPE (org.omegat.CLIParameters.PSEUDO_TRANSLATE_TYPE)1 PrepareTMXEntry (org.omegat.core.data.PrepareTMXEntry)1 ProjectProperties (org.omegat.core.data.ProjectProperties)1 RealProject (org.omegat.core.data.RealProject)1 SourceTextEntry (org.omegat.core.data.SourceTextEntry)1