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