Search in sources :

Example 1 with FilterMaster

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);
    }
}
Also used : FilterMaster(org.omegat.filters2.master.FilterMaster)

Example 2 with FilterMaster

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));
}
Also used : TextFilter(org.omegat.filters2.text.TextFilter) FilterMaster(org.omegat.filters2.master.FilterMaster) ResourceBundleFilter(org.omegat.filters2.text.bundles.ResourceBundleFilter) Segmenter(org.omegat.core.segmentation.Segmenter) File(java.io.File) Before(org.junit.Before)

Example 3 with FilterMaster

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;
}
Also used : FilterMaster(org.omegat.filters2.master.FilterMaster) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) FilterContext(org.omegat.filters2.FilterContext)

Example 4 with FilterMaster

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");
}
Also used : IFilter(org.omegat.filters2.IFilter) FilterMaster(org.omegat.filters2.master.FilterMaster) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) FilterContext(org.omegat.filters2.FilterContext)

Example 5 with FilterMaster

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");
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) FilterMaster(org.omegat.filters2.master.FilterMaster) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) KnownException(org.omegat.core.KnownException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) FilterContext(org.omegat.filters2.FilterContext)

Aggregations

FilterMaster (org.omegat.filters2.master.FilterMaster)16 File (java.io.File)9 Segmenter (org.omegat.core.segmentation.Segmenter)7 IOException (java.io.IOException)4 Before (org.junit.Before)4 FilterContext (org.omegat.filters2.FilterContext)4 RandomAccessFile (java.io.RandomAccessFile)3 Filters (gen.core.filters.Filters)2 CancellationException (java.util.concurrent.CancellationException)2 NotLoadedProject (org.omegat.core.data.NotLoadedProject)2 ISpellChecker (org.omegat.core.spellchecker.ISpellChecker)2 SpellChecker (org.omegat.core.spellchecker.SpellChecker)2 TagValidationTool (org.omegat.core.tagvalidation.TagValidationTool)2 SaveThread (org.omegat.core.threads.SaveThread)2 CommentsTextArea (org.omegat.gui.comments.CommentsTextArea)2 DictionariesTextArea (org.omegat.gui.dictionaries.DictionariesTextArea)2 EditorController (org.omegat.gui.editor.EditorController)2 ComesFromAutoTMMarker (org.omegat.gui.editor.mark.ComesFromAutoTMMarker)2 FontFallbackMarker (org.omegat.gui.editor.mark.FontFallbackMarker)2 NBSPMarker (org.omegat.gui.editor.mark.NBSPMarker)2