Search in sources :

Example 11 with TMXEntry

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

the class ComesFromAutoTMMarker method getMarksForEntry.

@Override
public synchronized List<Mark> getMarksForEntry(SourceTextEntry ste, String sourceText, String translationText, boolean isActive) {
    if (!Core.getEditor().getSettings().isMarkAutoPopulated()) {
        return null;
    }
    TMXEntry e = Core.getProject().getTranslationInfo(ste);
    if (e.linked == null) {
        return null;
    }
    Mark m = new Mark(Mark.ENTRY_PART.TRANSLATION, 0, translationText.length());
    switch(e.linked) {
        case xICE:
            m.painter = PAINTER_XICE;
            break;
        case x100PC:
            m.painter = PAINTER_X100PC;
            break;
        case xAUTO:
            m.painter = PAINTER_XAUTO;
            break;
        case xENFORCED:
            m.painter = PAINTER_XENFORCED;
    }
    return Collections.singletonList(m);
}
Also used : TMXEntry(org.omegat.core.data.TMXEntry)

Example 12 with TMXEntry

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

the class MatchesTextArea method checkForReplaceTranslation.

/**
 * if WORKFLOW_OPTION "Insert best fuzzy match into target field" is set
 *
 * RFE "Option: Insert best match (80%+) into target field"
 *
 * @see <a href="https://sourceforge.net/p/omegat/feature-requests/33/">RFE
 *      #33</a>
 */
private void checkForReplaceTranslation() {
    if (matches.isEmpty()) {
        return;
    }
    if (Preferences.isPreference(Preferences.BEST_MATCH_INSERT)) {
        int percentage = Preferences.getPreferenceDefault(Preferences.BEST_MATCH_MINIMAL_SIMILARITY, Preferences.BEST_MATCH_MINIMAL_SIMILARITY_DEFAULT);
        NearString thebest = matches.get(0);
        if (thebest.scores[0].score >= percentage) {
            SourceTextEntry currentEntry = Core.getEditor().getCurrentEntry();
            TMXEntry te = Core.getProject().getTranslationInfo(currentEntry);
            if (te != null && !te.isTranslated()) {
                String prefix = "";
                if (!Preferences.getPreference(Preferences.BEST_MATCH_EXPLANATORY_TEXT).isEmpty()) {
                    prefix = Preferences.getPreferenceDefault(Preferences.BEST_MATCH_EXPLANATORY_TEXT, OStrings.getString("WF_DEFAULT_PREFIX"));
                }
                String translation = thebest.translation;
                if (Preferences.isPreference(Preferences.CONVERT_NUMBERS)) {
                    translation = substituteNumbers(currentEntry.getSrcText(), thebest.source, thebest.translation);
                }
                Core.getEditor().replaceEditText(prefix + translation);
            }
        }
    }
}
Also used : SourceTextEntry(org.omegat.core.data.SourceTextEntry) NearString(org.omegat.core.matching.NearString) NearString(org.omegat.core.matching.NearString) Point(java.awt.Point) TMXEntry(org.omegat.core.data.TMXEntry)

Example 13 with TMXEntry

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

the class CalcStandardStatistics method buildProjectStats.

/**
 * Builds a file with statistic info about the project. The total word &
 * character count of the project, the total number of unique segments, plus
 * the details for each file.
 */
public static String buildProjectStats(final IProject project, final StatisticsInfo hotStat, final StatisticsPanel callback) {
    StatCount total = new StatCount();
    StatCount remaining = new StatCount();
    StatCount unique = new StatCount();
    StatCount remainingUnique = new StatCount();
    // find unique segments
    Map<String, SourceTextEntry> uniqueSegment = new HashMap<String, SourceTextEntry>();
    Set<String> translated = new HashSet<String>();
    for (SourceTextEntry ste : project.getAllEntries()) {
        String src = ste.getSrcText();
        for (ProtectedPart pp : ste.getProtectedParts()) {
            src = src.replace(pp.getTextInSourceSegment(), pp.getReplacementUniquenessCalculation());
        }
        if (!uniqueSegment.containsKey(src)) {
            uniqueSegment.put(src, ste);
        }
        TMXEntry tr = project.getTranslationInfo(ste);
        if (tr.isTranslated()) {
            translated.add(src);
        }
    }
    Set<String> filesUnique = new HashSet<String>();
    Set<String> filesRemainingUnique = new HashSet<String>();
    for (Map.Entry<String, SourceTextEntry> en : uniqueSegment.entrySet()) {
        /* Number of words and chars calculated without all tags and protected parts. */
        StatCount count = new StatCount(en.getValue());
        // add to unique
        unique.add(count);
        filesUnique.add(en.getValue().getKey().file);
        // add to unique remaining
        if (!translated.contains(en.getKey())) {
            remainingUnique.add(count);
            filesRemainingUnique.add(en.getValue().getKey().file);
        }
    }
    unique.addFiles(filesUnique.size());
    remainingUnique.addFiles(filesRemainingUnique.size());
    List<FileData> counts = new ArrayList<FileData>();
    Map<String, Boolean> firstSeenUniqueSegment = new HashMap<String, Boolean>();
    for (FileInfo file : project.getProjectFiles()) {
        FileData numbers = new FileData();
        numbers.filename = file.filePath;
        counts.add(numbers);
        int fileTotal = 0;
        int fileRemaining = 0;
        for (SourceTextEntry ste : file.entries) {
            String src = ste.getSrcText();
            for (ProtectedPart pp : ste.getProtectedParts()) {
                src = src.replace(pp.getTextInSourceSegment(), pp.getReplacementUniquenessCalculation());
            }
            /* Number of words and chars calculated without all tags and protected parts. */
            StatCount count = new StatCount(ste);
            // add to total
            total.add(count);
            fileTotal = 1;
            // add to remaining
            TMXEntry tr = project.getTranslationInfo(ste);
            if (!tr.isTranslated()) {
                remaining.add(count);
                fileRemaining = 1;
            }
            // add to file's info
            numbers.total.add(count);
            Boolean firstSeen = firstSeenUniqueSegment.get(src);
            if (firstSeen == null) {
                firstSeenUniqueSegment.put(src, false);
                numbers.unique.add(count);
                if (!tr.isTranslated()) {
                    numbers.remainingUnique.add(count);
                }
            }
            if (!tr.isTranslated()) {
                numbers.remaining.add(count);
            }
        }
        total.addFiles(fileTotal);
        remaining.addFiles(fileRemaining);
    }
    StringBuilder result = new StringBuilder();
    result.append(OStrings.getString("CT_STATS_Project_Statistics"));
    result.append("\n\n");
    String[][] headerTable = calcHeaderTable(new StatCount[] { total, remaining, unique, remainingUnique });
    if (callback != null) {
        callback.setProjectTableData(HT_HEADERS, headerTable);
    }
    result.append(TextUtil.showTextTable(HT_HEADERS, headerTable, HT_ALIGN));
    result.append("\n\n");
    // STATISTICS BY FILE
    result.append(OStrings.getString("CT_STATS_FILE_Statistics"));
    result.append("\n\n");
    String[][] filesTable = calcFilesTable(project.getProjectProperties(), counts);
    if (callback != null) {
        callback.setFilesTableData(FT_HEADERS, filesTable);
    }
    result.append(TextUtil.showTextTable(FT_HEADERS, filesTable, FT_ALIGN));
    if (hotStat != null) {
        hotStat.numberOfSegmentsTotal = total.segments;
        hotStat.numberofTranslatedSegments = translated.size();
        hotStat.numberOfUniqueSegments = unique.segments;
        hotStat.uniqueCountsByFile.clear();
        for (FileData fd : counts) {
            hotStat.uniqueCountsByFile.put(fd.filename, fd.unique.segments);
        }
    }
    return result.toString();
}
Also used : ProtectedPart(org.omegat.core.data.ProtectedPart) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FileInfo(org.omegat.core.data.IProject.FileInfo) SourceTextEntry(org.omegat.core.data.SourceTextEntry) HashMap(java.util.HashMap) Map(java.util.Map) TMXEntry(org.omegat.core.data.TMXEntry) HashSet(java.util.HashSet)

Example 14 with TMXEntry

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

the class SegmentBuilder method createActiveSegmentElement.

/**
 * Create active segment for given entry
 */
private void createActiveSegmentElement(TMXEntry trans) throws BadLocationException {
    try {
        if (EditorSettings.DISPLAY_MODIFICATION_INFO_ALL.equals(settings.getDisplayModificationInfo()) || EditorSettings.DISPLAY_MODIFICATION_INFO_SELECTED.equals(settings.getDisplayModificationInfo())) {
            addModificationInfoPart(trans);
        }
        int prevOffset = offset;
        sourceText = addInactiveSegPart(true, ste.getSrcText());
        Map<Language, ProjectTMX> otherLanguageTMs = Core.getProject().getOtherTargetLanguageTMs();
        for (Map.Entry<Language, ProjectTMX> entry : otherLanguageTMs.entrySet()) {
            TMXEntry altTrans = entry.getValue().getDefaultTranslation(ste.getSrcText());
            if (altTrans != null && altTrans.isTranslated()) {
                Language language = entry.getKey();
                addOtherLanguagePart(altTrans.translation, language);
            }
        }
        posSourceBeg = doc.createPosition(prevOffset + (hasRTL ? 1 : 0));
        posSourceLength = sourceText.length();
        if (trans.isTranslated()) {
            // translation exist
            translationText = trans.translation;
        } else {
            boolean insertSource = !Preferences.isPreference(Preferences.DONT_INSERT_SOURCE_TEXT);
            if (controller.entriesFilter != null && controller.entriesFilter.isSourceAsEmptyTranslation()) {
                insertSource = true;
            }
            if (insertSource) {
                // need to insert source text on empty translation
                String srcText = ste.getSrcText();
                if (Preferences.isPreference(Preferences.GLOSSARY_REPLACE_ON_INSERT)) {
                    srcText = EditorUtils.replaceGlossaryEntries(srcText);
                }
                translationText = srcText;
            } else {
                // empty text on non-exist translation
                translationText = "";
            }
        }
        translationText = addActiveSegPart(translationText);
        posTranslationBeg = null;
        doc.activeTranslationBeginM1 = doc.createPosition(activeTranslationBeginOffset - 1);
        doc.activeTranslationEndP1 = doc.createPosition(activeTranslationEndOffset + 1);
    } catch (OutOfMemoryError oome) {
        // Oh shit, we're all out of storage space!
        // Of course we should've cleaned up after ourselves earlier,
        // but since we didn't, do a bit of cleaning up now, otherwise
        // we can't even inform the user about our slacking off.
        doc.remove(0, doc.getLength());
        // Well, that cleared up some, GC to the rescue!
        System.gc();
        // There, that should do it, now inform the user
        long memory = Runtime.getRuntime().maxMemory() / 1024 / 1024;
        Log.logErrorRB("OUT_OF_MEMORY", memory);
        Log.log(oome);
        Core.getMainWindow().showErrorDialogRB("TF_ERROR", "OUT_OF_MEMORY", memory);
        // Just quit, we can't help it anyway
        System.exit(0);
    }
}
Also used : ProjectTMX(org.omegat.core.data.ProjectTMX) Language(org.omegat.util.Language) Map(java.util.Map) TMXEntry(org.omegat.core.data.TMXEntry)

Example 15 with TMXEntry

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

the class ReplaceFilter method replaceAll.

/**
 * Replace all occurrences in all entries.
 */
public void replaceAll() {
    for (SourceTextEntry ste : entries.values()) {
        TMXEntry en = Core.getProject().getTranslationInfo(ste);
        String trans = getEntryText(ste, en);
        if (trans == null) {
            continue;
        }
        // Avoid to replace more than once with variables when entries have duplicates
        if ((en.defaultTranslation) && (ste.getDuplicate() == SourceTextEntry.DUPLICATE.NEXT)) {
            // Already replaced when we parsed the first entry
            continue;
        }
        List<SearchMatch> found = getReplacementsForEntry(trans);
        if (found != null) {
            int off = 0;
            StringBuilder o = new StringBuilder(trans);
            for (SearchMatch m : found) {
                o.replace(m.getStart() + off, m.getEnd() + off, m.getReplacement());
                off += m.getReplacement().length() - m.getLength();
            }
            PrepareTMXEntry prepare = new PrepareTMXEntry(en);
            prepare.translation = o.toString();
            Core.getProject().setTranslation(ste, prepare, en.defaultTranslation, null);
        }
    }
    EditorController ec = (EditorController) Core.getEditor();
    ec.refreshEntries(entries.keySet());
}
Also used : SearchMatch(org.omegat.core.search.SearchMatch) EditorController(org.omegat.gui.editor.EditorController) SourceTextEntry(org.omegat.core.data.SourceTextEntry) PrepareTMXEntry(org.omegat.core.data.PrepareTMXEntry) PrepareTMXEntry(org.omegat.core.data.PrepareTMXEntry) TMXEntry(org.omegat.core.data.TMXEntry)

Aggregations

TMXEntry (org.omegat.core.data.TMXEntry)20 SourceTextEntry (org.omegat.core.data.SourceTextEntry)13 PrepareTMXEntry (org.omegat.core.data.PrepareTMXEntry)10 Map (java.util.Map)7 HashMap (java.util.HashMap)5 Point (java.awt.Point)4 EntryKey (org.omegat.core.data.EntryKey)4 IProject (org.omegat.core.data.IProject)4 Language (org.omegat.util.Language)4 ArrayList (java.util.ArrayList)3 NearString (org.omegat.core.matching.NearString)3 File (java.io.File)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 ExternalTMX (org.omegat.core.data.ExternalTMX)2 FileInfo (org.omegat.core.data.IProject.FileInfo)2 ITMXEntry (org.omegat.core.data.ITMXEntry)2 ProjectTMX (org.omegat.core.data.ProjectTMX)2 ProtectedPart (org.omegat.core.data.ProtectedPart)2 SearchMatch (org.omegat.core.search.SearchMatch)2