Search in sources :

Example 1 with RealProject

use of org.omegat.core.data.RealProject in project omegat by omegat-org.

the class Main method selectProjectConsoleMode.

/**
 * creates the project class and adds it to the Core. Loads the project if
 * specified. An exit occurs on error loading the project. This method is
 * for the different console modes, to prevent code duplication.
 *
 * @param loadProject
 *            load the project or not
 * @return the project.
 */
private static RealProject selectProjectConsoleMode(boolean loadProject) {
    System.out.println(OStrings.getString("CONSOLE_LOADING_PROJECT"));
    // check if project okay
    ProjectProperties projectProperties = null;
    try {
        projectProperties = ProjectFileStorage.loadProjectProperties(projectLocation);
        projectProperties.verifyProject();
    } catch (Exception ex) {
        Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
        System.out.println(OStrings.getString("PP_ERROR_UNABLE_TO_READ_PROJECT_FILE"));
        System.exit(1);
    }
    RealProject p = new RealProject(projectProperties);
    Core.setProject(p);
    if (loadProject) {
        p.loadProject(true);
        if (!p.isProjectLoaded()) {
            Core.setProject(new NotLoadedProject());
        } else {
            executeConsoleScript(IProjectEventListener.PROJECT_CHANGE_TYPE.LOAD);
        }
    }
    return p;
}
Also used : NotLoadedProject(org.omegat.core.data.NotLoadedProject) ProjectProperties(org.omegat.core.data.ProjectProperties) RealProject(org.omegat.core.data.RealProject) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 2 with RealProject

use of org.omegat.core.data.RealProject in project omegat by omegat-org.

the class Main method runConsoleTranslate.

/**
 * Execute in console mode for translate.
 */
protected static int runConsoleTranslate() throws Exception {
    Log.log("Console translation mode");
    Log.log("");
    System.out.println(OStrings.getString("CONSOLE_INITIALIZING"));
    Core.initializeConsole(PARAMS);
    RealProject p = selectProjectConsoleMode(true);
    validateTagsConsoleMode();
    System.out.println(OStrings.getString("CONSOLE_TRANSLATING"));
    String sourceMask = PARAMS.get(CLIParameters.SOURCE_PATTERN);
    if (sourceMask != null) {
        p.compileProject(sourceMask, false);
    } else {
        p.compileProject(".*", false);
    }
    // Called *after* executing post processing command (unlike the
    // regular PROJECT_CHANGE_TYPE.COMPILE)
    executeConsoleScript(IProjectEventListener.PROJECT_CHANGE_TYPE.COMPILE);
    p.closeProject();
    executeConsoleScript(IProjectEventListener.PROJECT_CHANGE_TYPE.CLOSE);
    System.out.println(OStrings.getString("CONSOLE_FINISHED"));
    return 0;
}
Also used : RealProject(org.omegat.core.data.RealProject)

Example 3 with RealProject

use of org.omegat.core.data.RealProject 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)

Example 4 with RealProject

use of org.omegat.core.data.RealProject in project omegat by omegat-org.

the class Main method runConsoleAlign.

public static int runConsoleAlign() throws Exception {
    Log.log("Console alignment mode");
    Log.log("");
    if (projectLocation == null) {
        System.out.println(OStrings.getString("PP_ERROR_UNABLE_TO_READ_PROJECT_FILE"));
        return 1;
    }
    String dir = PARAMS.get(CLIParameters.ALIGNDIR);
    if (dir == null) {
        System.out.println(OStrings.getString("CONSOLE_TRANSLATED_FILES_LOC_UNDEFINED"));
        return 1;
    }
    System.out.println(OStrings.getString("CONSOLE_INITIALIZING"));
    Core.initializeConsole(PARAMS);
    RealProject p = selectProjectConsoleMode(true);
    validateTagsConsoleMode();
    System.out.println(StringUtil.format(OStrings.getString("CONSOLE_ALIGN_AGAINST"), dir));
    Map<String, TMXEntry> data = p.align(p.getProjectProperties(), new File(dir));
    Map<String, PrepareTMXEntry> result = new TreeMap<>();
    for (Map.Entry<String, TMXEntry> en : data.entrySet()) {
        result.put(en.getKey(), new PrepareTMXEntry(en.getValue()));
    }
    String tmxFile = p.getProjectProperties().getProjectInternal() + "align.tmx";
    TMXWriter.buildTMXFile(tmxFile, false, false, p.getProjectProperties(), result);
    p.closeProject();
    System.out.println(OStrings.getString("CONSOLE_FINISHED"));
    return 0;
}
Also used : RealProject(org.omegat.core.data.RealProject) TreeMap(java.util.TreeMap) File(java.io.File) PrepareTMXEntry(org.omegat.core.data.PrepareTMXEntry) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) TMXEntry(org.omegat.core.data.TMXEntry) PrepareTMXEntry(org.omegat.core.data.PrepareTMXEntry)

Aggregations

RealProject (org.omegat.core.data.RealProject)4 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 PrepareTMXEntry (org.omegat.core.data.PrepareTMXEntry)2 ProjectProperties (org.omegat.core.data.ProjectProperties)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 PSEUDO_TRANSLATE_TYPE (org.omegat.CLIParameters.PSEUDO_TRANSLATE_TYPE)1 NotLoadedProject (org.omegat.core.data.NotLoadedProject)1 SourceTextEntry (org.omegat.core.data.SourceTextEntry)1 TMXEntry (org.omegat.core.data.TMXEntry)1