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;
}
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;
}
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;
}
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;
}
Aggregations