use of org.omegat.filters2.master.FilterMaster in project omegat by omegat-org.
the class FiltersCustomizerController method persist.
@Override
public void persist() {
if (!isProjectSpecific) {
Core.setFilterMaster(new FilterMaster(editableFilters));
Preferences.setFilters(editableFilters);
}
}
use of org.omegat.filters2.master.FilterMaster in project omegat by omegat-org.
the class AlignerTest method setUp.
@Before
public final void setUp() {
FilterMaster.setFilterClasses(Arrays.asList(TextFilter.class, ResourceBundleFilter.class));
Core.setFilterMaster(new FilterMaster(FilterMaster.createDefaultFiltersConfig()));
Core.setSegmenter(new Segmenter(SRX.getDefault()));
assertTrue(Core.getFilterMaster().isFileSupported(new File("blah.txt"), true));
assertTrue(Core.getFilterMaster().isFileSupported(new File("blah.properties"), true));
}
use of org.omegat.filters2.master.FilterMaster in project omegat by omegat-org.
the class RealProject method align.
/**
* Align project.
*/
public Map<String, TMXEntry> align(final ProjectProperties props, final File translatedDir) throws Exception {
FilterMaster fm = Core.getFilterMaster();
File root = new File(config.getSourceRoot());
List<File> srcFileList = FileUtil.buildFileList(root, true);
AlignFilesCallback alignFilesCallback = new AlignFilesCallback(props);
String srcRoot = config.getSourceRoot();
for (File file : srcFileList) {
// shorten filename to that which is relative to src root
String midName = file.getPath().substring(srcRoot.length());
fm.alignFile(srcRoot, midName, translatedDir.getPath(), new FilterContext(props), alignFilesCallback);
}
return alignFilesCallback.data;
}
use of org.omegat.filters2.master.FilterMaster in project omegat by omegat-org.
the class RealProject method loadSourceFiles.
/**
* Load source files for project.
*/
private void loadSourceFiles() throws Exception {
long st = System.currentTimeMillis();
FilterMaster fm = Core.getFilterMaster();
File root = new File(config.getSourceRoot());
List<String> srcPathList = FileUtil.buildRelativeFilesList(root, Collections.emptyList(), config.getSourceRootExcludes()).stream().sorted(StreamUtil.comparatorByList(getSourceFilesOrder())).collect(Collectors.toList());
for (String filepath : srcPathList) {
Core.getMainWindow().showStatusMessageRB("CT_LOAD_FILE_MX", filepath);
LoadFilesCallback loadFilesCallback = new LoadFilesCallback(existSource, existKeys, transMemories);
FileInfo fi = new FileInfo();
fi.filePath = filepath;
loadFilesCallback.setCurrentFile(fi);
IFilter filter = fm.loadFile(config.getSourceRoot() + filepath, new FilterContext(config), loadFilesCallback);
loadFilesCallback.fileFinished();
if (filter != null && !fi.entries.isEmpty()) {
// Don't store the instance, because every file gets an instance and
fi.filterClass = filter.getClass();
// then we consume a lot of memory for all instances.
// See also IFilter "TODO: each filter should be stateless"
fi.filterFileFormatName = filter.getFileFormatName();
try {
fi.fileEncoding = filter.getInEncodingLastParsedFile();
} catch (Error e) {
// In case a filter doesn't have getInEncodingLastParsedFile() (e.g., Okapi plugin)
fi.fileEncoding = "";
}
projectFilesList.add(fi);
}
}
findNonUniqueSegments();
Core.getMainWindow().showStatusMessageRB("CT_LOAD_SRC_COMPLETE");
long en = System.currentTimeMillis();
Log.log("Load project source files: " + (en - st) + "ms");
}
use of org.omegat.filters2.master.FilterMaster in project omegat by omegat-org.
the class RealProject method compileProjectAndCommit.
/**
* Builds translated files corresponding to sourcePattern and creates fresh TM files.
*
* @param sourcePattern
* The regexp of files to create
* @param doPostProcessing
* Whether or not we should perform external post-processing.
* @param commitTargetFiles
* Whether or not we should commit target files
* @throws Exception
*/
@Override
public void compileProjectAndCommit(String sourcePattern, boolean doPostProcessing, boolean commitTargetFiles) throws Exception {
Log.logInfoRB("LOG_DATAENGINE_COMPILE_START");
UIThreadsUtil.mustNotBeSwingThread();
Pattern filePattern = Pattern.compile(sourcePattern);
// - TMX Level 2, with OmegaT formatting tags wrapped in TMX inline tags
try {
// build TMX with OmegaT tags
String fname = config.getProjectRoot() + config.getProjectName() + OConsts.OMEGAT_TMX + OConsts.TMX_EXTENSION;
projectTMX.exportTMX(config, new File(fname), false, false, false);
// build TMX level 1 compliant file
fname = config.getProjectRoot() + config.getProjectName() + OConsts.LEVEL1_TMX + OConsts.TMX_EXTENSION;
projectTMX.exportTMX(config, new File(fname), true, false, false);
// build three-quarter-assed TMX level 2 file
fname = config.getProjectRoot() + config.getProjectName() + OConsts.LEVEL2_TMX + OConsts.TMX_EXTENSION;
projectTMX.exportTMX(config, new File(fname), false, true, false);
} catch (Exception e) {
Log.logErrorRB("CT_ERROR_CREATING_TMX");
Log.log(e);
throw new IOException(OStrings.getString("CT_ERROR_CREATING_TMX") + "\n" + e.getMessage());
}
String srcRoot = config.getSourceRoot();
String locRoot = config.getTargetRoot();
// build translated files
FilterMaster fm = Core.getFilterMaster();
List<String> pathList = FileUtil.buildRelativeFilesList(new File(srcRoot), Collections.emptyList(), config.getSourceRootExcludes());
TranslateFilesCallback translateFilesCallback = new TranslateFilesCallback();
int numberOfCompiled = 0;
for (String midName : pathList) {
// shorten filename to that which is relative to src root
Matcher fileMatch = filePattern.matcher(midName);
if (fileMatch.matches()) {
File fn = new File(locRoot, midName);
if (!fn.getParentFile().exists()) {
// target directory doesn't exist - create it
if (!fn.getParentFile().mkdirs()) {
throw new IOException(OStrings.getString("CT_ERROR_CREATING_TARGET_DIR") + fn.getParentFile());
}
}
Core.getMainWindow().showStatusMessageRB("CT_COMPILE_FILE_MX", midName);
translateFilesCallback.fileStarted(midName);
fm.translateFile(srcRoot, midName, locRoot, new FilterContext(config), translateFilesCallback);
translateFilesCallback.fileFinished();
numberOfCompiled++;
}
}
if (remoteRepositoryProvider != null && config.getTargetDir().isUnderRoot() && commitTargetFiles && isOnlineMode) {
tmxPrepared = null;
glossaryPrepared = null;
// commit translations
try {
Core.getMainWindow().showStatusMessageRB("TF_COMMIT_TARGET_START");
remoteRepositoryProvider.switchAllToLatest();
remoteRepositoryProvider.copyFilesFromProjectToRepos(config.getTargetDir().getUnderRoot(), null);
remoteRepositoryProvider.commitFiles(config.getTargetDir().getUnderRoot(), "Project translation");
Core.getMainWindow().showStatusMessageRB("TF_COMMIT_TARGET_DONE");
} catch (Exception e) {
Log.logErrorRB("TF_COMMIT_TARGET_ERROR");
Log.log(e);
throw new IOException(OStrings.getString("TF_COMMIT_TARGET_ERROR") + "\n" + e.getMessage());
}
}
if (numberOfCompiled == 1) {
Core.getMainWindow().showStatusMessageRB("CT_COMPILE_DONE_MX_SINGULAR");
} else {
Core.getMainWindow().showStatusMessageRB("CT_COMPILE_DONE_MX");
}
CoreEvents.fireProjectChange(IProjectEventListener.PROJECT_CHANGE_TYPE.COMPILE);
if (doPostProcessing) {
// Kill any processes still not complete
flushProcessCache();
if (Preferences.isPreference(Preferences.ALLOW_PROJECT_EXTERN_CMD)) {
doExternalCommand(config.getExternalCommand());
}
doExternalCommand(Preferences.getPreference(Preferences.EXTERNAL_COMMAND));
}
Log.logInfoRB("LOG_DATAENGINE_COMPILE_END");
}
Aggregations