Search in sources :

Example 11 with SourceTextEntry

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

the class EditorTextArea3 method wholeTagDelete.

/**
 * Whole tag delete before or after cursor
 *
 * @param checkTagStart
 *            true if check tag start, false if check tag end
 * @return true if tag deleted
 */
boolean wholeTagDelete(boolean checkTagStart) throws BadLocationException {
    Document3 doc = getOmDocument();
    SourceTextEntry ste = doc.controller.getCurrentEntry();
    String text = doc.extractTranslation();
    int off = getCaretPosition() - doc.getTranslationStart();
    // iterate by 'protected parts'
    if (ste != null) {
        for (ProtectedPart pp : ste.getProtectedParts()) {
            if (checkTagStart) {
                if (StringUtil.isSubstringAfter(text, off, pp.getTextInSourceSegment())) {
                    int pos = off + doc.getTranslationStart();
                    doc.remove(pos, pp.getTextInSourceSegment().length());
                    return true;
                }
            } else {
                if (StringUtil.isSubstringBefore(text, off, pp.getTextInSourceSegment())) {
                    int pos = off + doc.getTranslationStart() - pp.getTextInSourceSegment().length();
                    doc.remove(pos, pp.getTextInSourceSegment().length());
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : ProtectedPart(org.omegat.core.data.ProtectedPart) SourceTextEntry(org.omegat.core.data.SourceTextEntry) Point(java.awt.Point)

Example 12 with SourceTextEntry

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

the class ReplaceFilter method skip.

private void skip() {
    EditorController ec = (EditorController) Core.getEditor();
    // try to find in current entry
    int pos = ec.getCurrentPositionInEntryTranslation();
    String str = ec.getCurrentTranslation();
    List<SearchMatch> found = getReplacementsForEntry(str);
    if (found != null) {
        for (SearchMatch m : found) {
            if (m.getStart() >= pos) {
                ec.setCaretPosition(new IEditor.CaretPosition(m.getStart(), m.getEnd()));
                ec.requestFocus();
                return;
            }
        }
    }
    // not found in current entry - find next entry
    int currentEntryNumber = ec.getCurrentEntryNumber();
    ec.commitAndDeactivate();
    // find to the end of project
    for (int i = currentEntryNumber + 1; i <= maxEntryNum; i++) {
        SourceTextEntry ste = entries.get(i);
        if (ste == null) {
            // entry not filtered
            continue;
        }
        TMXEntry en = Core.getProject().getTranslationInfo(ste);
        String trans = getEntryText(ste, en);
        if (trans == null) {
            continue;
        }
        found = getReplacementsForEntry(trans);
        if (found == null) {
            // no replacements
            continue;
        }
        for (SearchMatch m : found) {
            ec.gotoEntry(i, new CaretPosition(m.getStart(), m.getEnd()));
            ec.requestFocus();
            return;
        }
    }
    // find from the beginning of project
    for (int i = minEntryNum; i < currentEntryNumber; i++) {
        SourceTextEntry ste = entries.get(i);
        if (ste == null) {
            // entry not filtered
            continue;
        }
        TMXEntry en = Core.getProject().getTranslationInfo(ste);
        String trans = getEntryText(ste, en);
        if (trans == null) {
            continue;
        }
        found = getReplacementsForEntry(trans);
        if (found == null) {
            // no replacements
            continue;
        }
        for (SearchMatch m : found) {
            ec.gotoEntry(i, new CaretPosition(m.getStart(), m.getEnd()));
            ec.requestFocus();
            return;
        }
    }
    // not found
    ec.activateEntry();
}
Also used : IEditor(org.omegat.gui.editor.IEditor) EditorController(org.omegat.gui.editor.EditorController) SearchMatch(org.omegat.core.search.SearchMatch) SourceTextEntry(org.omegat.core.data.SourceTextEntry) CaretPosition(org.omegat.gui.editor.IEditor.CaretPosition) CaretPosition(org.omegat.gui.editor.IEditor.CaretPosition) PrepareTMXEntry(org.omegat.core.data.PrepareTMXEntry) TMXEntry(org.omegat.core.data.TMXEntry)

Example 13 with SourceTextEntry

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

the class XLIFFFilterTest method testTags.

@Test
public void testTags() throws Exception {
    String f = "test/data/filters/xliff/file-XLIFFFilter-tags.xlf";
    IProject.FileInfo fi = loadSourceFiles(filter, f);
    SourceTextEntry ste;
    checkMultiStart(fi, f);
    // #1988732
    checkMultiNoPrevNext("Link to <m0>http://localhost</m0>.", null, null, null);
    // #1988732
    checkMultiNoPrevNext("About <b0>Gandalf</b0>", null, null, "7");
    checkMultiNoPrevNext("<i0>Tags</i0> translation zz<i1>2</i1>z <b2>-NONTRANSLATED", null, null, null);
    checkMultiNoPrevNext("one <a0> two </b1> three <c2> four </d3> five", null, null, null);
    ste = checkMultiNoPrevNext("About <m0>Gandalf</m0> and <m1>other</m1>.", null, null, null);
    assertEquals(3, ste.getProtectedParts().length);
    assertEquals("<m0>Gandalf</m0>", ste.getProtectedParts()[0].getTextInSourceSegment());
    assertEquals("<mrk mtype=\"protected\">Gandalf</mrk>", ste.getProtectedParts()[0].getDetailsFromSourceFile());
    assertEquals("Gandalf", ste.getProtectedParts()[0].getReplacementMatchCalculation());
    assertEquals("<m1>", ste.getProtectedParts()[1].getTextInSourceSegment());
    assertEquals("<mrk mtype=\"other\">", ste.getProtectedParts()[1].getDetailsFromSourceFile());
    assertEquals(StaticUtils.TAG_REPLACEMENT, ste.getProtectedParts()[1].getReplacementMatchCalculation());
    assertEquals("</m1>", ste.getProtectedParts()[2].getTextInSourceSegment());
    assertEquals("</mrk>", ste.getProtectedParts()[2].getDetailsFromSourceFile());
    assertEquals(StaticUtils.TAG_REPLACEMENT, ste.getProtectedParts()[2].getReplacementMatchCalculation());
    checkMultiNoPrevNext("one <o0>two</o0> three", null, null, null);
    checkMultiNoPrevNext("one <t0/> three", null, null, null);
    checkMultiNoPrevNext("one <w0/> three", null, null, null);
    checkMultiNoPrevNext("Nested tags: before <g0><g1><x2/></g1></g0> after", null, null, null);
    checkMultiNoPrevNext("<m0>Check protected-only tag reading</m0>", null, null, null);
    checkMultiEnd();
    File inFile = new File("test/data/filters/xliff/file-XLIFFFilter-tags.xlf");
    filter.translateFile(inFile, outFile, new TreeMap<String, String>(), context, new ITranslateCallback() {

        public String getTranslation(String id, String source, String path) {
            return source.replace("NONTRANSLATED", "TRANSLATED");
        }

        public String getTranslation(String id, String source) {
            return source.replace("NONTRANSLATED", "TRANSLATED");
        }

        public void linkPrevNextSegments() {
        }

        public void setPass(int pass) {
        }
    });
    File trFile = new File(outFile.getPath() + "-translated");
    List<String> lines = Files.lines(inFile.toPath()).map(line -> line.replace("NONTRANSLATED", "TRANSLATED")).collect(Collectors.toList());
    Files.write(trFile.toPath(), lines);
    compareXML(trFile, outFile);
}
Also used : SourceTextEntry(org.omegat.core.data.SourceTextEntry) URISyntaxException(java.net.URISyntaxException) StatCount(org.omegat.core.statistics.StatCount) PatternConsts(org.omegat.util.PatternConsts) StaticUtils(org.omegat.util.StaticUtils) TranslationException(org.omegat.filters2.TranslationException) Core(org.omegat.core.Core) Assert.fail(org.junit.Assert.fail) XLIFFFilter(org.omegat.filters3.xml.xliff.XLIFFFilter) Before(org.junit.Before) IProject(org.omegat.core.data.IProject) ITranslateCallback(org.omegat.filters2.ITranslateCallback) Files(java.nio.file.Files) Assert.assertTrue(org.junit.Assert.assertTrue) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) XLIFFOptions(org.omegat.filters3.xml.xliff.XLIFFOptions) Collectors(java.util.stream.Collectors) File(java.io.File) StatisticsSettings(org.omegat.core.statistics.StatisticsSettings) List(java.util.List) XLIFFDialect(org.omegat.filters3.xml.xliff.XLIFFDialect) TreeMap(java.util.TreeMap) Assert.assertFalse(org.junit.Assert.assertFalse) SAXException(org.xml.sax.SAXException) Preferences(org.omegat.util.Preferences) Assert.assertEquals(org.junit.Assert.assertEquals) ITranslateCallback(org.omegat.filters2.ITranslateCallback) SourceTextEntry(org.omegat.core.data.SourceTextEntry) File(java.io.File) IProject(org.omegat.core.data.IProject) Test(org.junit.Test)

Example 14 with SourceTextEntry

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

the class FalseFriendsTest method setUp.

@Before
public final void setUp() {
    final ProjectProperties props = new ProjectProperties() {

        public Language getSourceLanguage() {
            return new Language("en");
        }

        public Language getTargetLanguage() {
            return new Language("pl");
        }
    };
    Core.setProject(new IProject() {

        public void setTranslation(SourceTextEntry entry, PrepareTMXEntry trans, boolean defaultTranslation, TMXEntry.ExternalLinked externalLinked) {
        }

        public void setTranslation(SourceTextEntry entry, PrepareTMXEntry trans, boolean defaultTranslation, ExternalLinked externalLinked, AllTranslations previousTranslations) throws OptimisticLockingFail {
        }

        public void setNote(SourceTextEntry entry, TMXEntry oldTrans, String note) {
        }

        public void saveProjectProperties() throws Exception {
        }

        public void saveProject(boolean doTeamSync) {
        }

        public void iterateByMultipleTranslations(MultipleTranslationsIterator it) {
        }

        public void iterateByDefaultTranslations(DefaultTranslationsIterator it) {
        }

        public boolean isProjectModified() {
            return false;
        }

        public boolean isProjectLoaded() {
            return true;
        }

        public boolean isOrphaned(EntryKey entry) {
            return false;
        }

        public boolean isOrphaned(String source) {
            return false;
        }

        public TMXEntry getTranslationInfo(SourceTextEntry ste) {
            return null;
        }

        public AllTranslations getAllTranslations(SourceTextEntry ste) {
            return null;
        }

        public Map<String, ExternalTMX> getTransMemories() {
            return null;
        }

        public ITokenizer getTargetTokenizer() {
            return null;
        }

        public StatisticsInfo getStatistics() {
            return null;
        }

        public ITokenizer getSourceTokenizer() {
            return null;
        }

        public ProjectProperties getProjectProperties() {
            return props;
        }

        public List<FileInfo> getProjectFiles() {
            return null;
        }

        public Map<Language, ProjectTMX> getOtherTargetLanguageTMs() {
            return null;
        }

        public List<SourceTextEntry> getAllEntries() {
            return null;
        }

        public void compileProject(String sourcePattern) throws Exception {
        }

        public void closeProject() {
        }

        public List<String> getSourceFilesOrder() {
            return null;
        }

        public void setSourceFilesOrder(List<String> filesList) {
        }

        @Override
        public String getTargetPathForSourceFile(String sourceFile) {
            return null;
        }

        @Override
        public boolean isTeamSyncPrepared() {
            return false;
        }

        @Override
        public void teamSync() {
        }

        @Override
        public void teamSyncPrepare() throws Exception {
        }

        @Override
        public boolean isRemoteProject() {
            return false;
        }

        @Override
        public void commitSourceFiles() throws Exception {
        }

        @Override
        public void compileProjectAndCommit(String sourcePattern, boolean doPostProcessing, boolean commitTargetFiles) throws Exception {
        }
    });
    LanguageToolWrapper.setBridgeFromCurrentProject();
}
Also used : ExternalLinked(org.omegat.core.data.TMXEntry.ExternalLinked) EntryKey(org.omegat.core.data.EntryKey) StatisticsInfo(org.omegat.core.statistics.StatisticsInfo) ProjectProperties(org.omegat.core.data.ProjectProperties) IProject(org.omegat.core.data.IProject) ExternalLinked(org.omegat.core.data.TMXEntry.ExternalLinked) ITokenizer(org.omegat.tokenizer.ITokenizer) Language(org.omegat.util.Language) SourceTextEntry(org.omegat.core.data.SourceTextEntry) List(java.util.List) PrepareTMXEntry(org.omegat.core.data.PrepareTMXEntry) Map(java.util.Map) PrepareTMXEntry(org.omegat.core.data.PrepareTMXEntry) TMXEntry(org.omegat.core.data.TMXEntry) Before(org.junit.Before)

Example 15 with SourceTextEntry

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

the class CalcMatchStatistics method forFile.

MatchStatCounts forFile(IProject.FileInfo fi) {
    MatchStatCounts result = new MatchStatCounts();
    alreadyProcessedInFile.clear();
    final List<SourceTextEntry> untranslatedEntries = new ArrayList<SourceTextEntry>();
    // We should iterate all segments from file.
    for (SourceTextEntry ste : fi.entries) {
        checkInterrupted();
        StatCount count = new StatCount(ste);
        boolean existInFile = alreadyProcessedInFile.contains(ste.getSrcText());
        boolean existInPreviousFiles = alreadyProcessedInProject.contains(ste.getSrcText());
        if (Core.getProject().getTranslationInfo(ste).isTranslated()) {
            // segment has translation - should be calculated as
            // "Exact matched"
            result.addExact(count);
            treated++;
        } else if (existInPreviousFiles) {
            // exist in other file
            result.addRepetitionFromOtherFiles(count);
            entryProcessed();
        } else if (existInFile) {
            // exist in this file
            result.addRepetitionWithinThisFile(count);
            entryProcessed();
        } else {
            // first time
            untranslatedEntries.add(ste);
            alreadyProcessedInFile.add(ste.getSrcText());
        }
    }
    alreadyProcessedInProject.addAll(alreadyProcessedInFile);
    calcSimilarity(untranslatedEntries).ifPresent(result::addCounts);
    return result;
}
Also used : SourceTextEntry(org.omegat.core.data.SourceTextEntry) ArrayList(java.util.ArrayList)

Aggregations

SourceTextEntry (org.omegat.core.data.SourceTextEntry)32 Point (java.awt.Point)14 TMXEntry (org.omegat.core.data.TMXEntry)12 PrepareTMXEntry (org.omegat.core.data.PrepareTMXEntry)9 ArrayList (java.util.ArrayList)8 IProject (org.omegat.core.data.IProject)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 EntryKey (org.omegat.core.data.EntryKey)5 FileInfo (org.omegat.core.data.IProject.FileInfo)5 Language (org.omegat.util.Language)5 List (java.util.List)4 Before (org.junit.Before)4 ProtectedPart (org.omegat.core.data.ProtectedPart)4 NearString (org.omegat.core.matching.NearString)4 Cursor (java.awt.Cursor)3 File (java.io.File)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Locale (java.util.Locale)2