Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Change Editor color customizer label #1051

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/org/omegat/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2532,7 +2532,7 @@ COLOR_REMOVETEXT_TARGET=Flagged text
COLOR_NBSP=Non-breakable spaces
COLOR_WHITESPACE=Whitespaces
COLOR_BIDIMARKERS=Bidirectional control characters
COLOR_MARK_COMES_FROM_TM=From memory
COLOR_MARK_COMES_FROM_TM_MT=From MT memory
COLOR_MARK_COMES_FROM_TM_XICE=From ICE memory
COLOR_MARK_COMES_FROM_TM_X100PC=From 100% memory
COLOR_MARK_COMES_FROM_TM_XAUTO=From auto memory
Expand Down
2 changes: 1 addition & 1 deletion src/org/omegat/Bundle_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2325,7 +2325,7 @@ COLOR_REMOVETEXT_TARGET=\u30D5\u30E9\u30B0\u4ED8\u304D\u6587\u5B57\u5217
COLOR_NBSP=\u30CE\u30FC\u30D6\u30EC\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9
COLOR_WHITESPACE=\u7A7A\u767D\u6587\u5B57
COLOR_BIDIMARKERS=\u53CC\u65B9\u5411\u30A2\u30EB\u30B4\u30EA\u30BA\u30E0\u5236\u5FA1\u6587\u5B57
COLOR_MARK_COMES_FROM_TM=\u5185\u90E8\u30E1\u30E2\u30EA\u7531\u6765\u306E\u5206\u7BC0
COLOR_MARK_COMES_FROM_TM_MT=MT\u30E1\u30E2\u30EA\u7531\u6765\u306E\u5206\u7BC0
COLOR_MARK_COMES_FROM_TM_XICE=ICE \u30E1\u30E2\u30EA\u7531\u6765\u306E\u5206\u7BC0
COLOR_MARK_COMES_FROM_TM_X100PC=100% \u30E1\u30E2\u30EA\u7531\u6765\u306E\u5206\u7BC0
COLOR_MARK_COMES_FROM_TM_XAUTO=auto \u30E1\u30E2\u30EA\u7531\u6765\u306E\u5206\u7BC0
Expand Down
2 changes: 1 addition & 1 deletion src/org/omegat/ColorScheme_dark.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ OmegaT.nbsp=#c8c8c8
OmegaT.whiteSpace=#808080
OmegaT.bidiMarkers=#c80000
OmegaT.paragraphStart=#aeaeae
OmegaT.markComesFromTm=#fa8072
OmegaT.markComesFromTmMt=#fa8072
OmegaT.markComesFromTmXice=#af76df
OmegaT.markComesFromTmX100pc=#ff9408
OmegaT.markComesFromTmXauto=#ffd596
Expand Down
2 changes: 1 addition & 1 deletion src/org/omegat/ColorScheme_light.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ OmegaT.nbsp=#c8c8c8
OmegaT.whiteSpace=#808080
OmegaT.bidiMarkers=#c80000
OmegaT.paragraphStart=#aeaeae
OmegaT.markComesFromTm=#fa8072
OmegaT.markComesFromTmMt=#fa8072
OmegaT.markComesFromTmXice=#af76df
OmegaT.markComesFromTmX100pc=#ff9408
OmegaT.markComesFromTmXauto=#ffd596
Expand Down
4 changes: 2 additions & 2 deletions src/org/omegat/gui/editor/mark/ComesFromMTMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void onEntryActivated(SourceTextEntry newEntry) {
}
});
highlightPainter = new TransparentHighlightPainter(
Styles.EditorColor.COLOR_MARK_COMES_FROM_TM.getColor(), 0.5F);
Styles.EditorColor.COLOR_MARK_COMES_FROM_TM_MT.getColor(), 0.5F);
}

public void setMark(SourceTextEntry ste, String text) {
Expand All @@ -73,7 +73,7 @@ public void setMark(SourceTextEntry ste, String text) {
public synchronized List<Mark> getMarksForEntry(SourceTextEntry ste, String sourceText, String translationText,
boolean isActive) {
synchronized (this) {
if (!isActive || ste != markedSte || !translationText.equals(markedText)) {
miurahr marked this conversation as resolved.
Show resolved Hide resolved
if (!isActive || ste != markedSte || translationText == null || !translationText.equals(markedText)) {
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/omegat/util/gui/Styles.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public enum EditorColor {

COLOR_PARAGRAPH_START(UIManager.getColor("OmegaT.paragraphStart")),

COLOR_MARK_COMES_FROM_TM(UIManager.getColor("OmegaT.markComesFromTm")),
COLOR_MARK_COMES_FROM_TM_MT(UIManager.getColor("OmegaT.markComesFromTmMt")),

COLOR_MARK_COMES_FROM_TM_XICE(UIManager.getColor("OmegaT.markComesFromTmXice")),

Expand Down
15 changes: 15 additions & 0 deletions test/data/tmx/mt/mt1.tmx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tmx SYSTEM "tmx14.dtd">
<tmx version="1.4">
<header datatype="plaintext" srclang="en-US" adminlang="EN-US" o-tmf="OmegaT TMX" segtype="paragraph" creationtoolversion="test" creationtool="test"/>
<body>
<tu>
<tuv xml:lang="en">
<seg>source</seg>
</tuv>
<tuv xml:lang="fr">
<seg>target</seg>
</tuv>
</tu>
</body>
</tmx>
161 changes: 161 additions & 0 deletions test/src/org/omegat/gui/editor/mark/ComesFromMTMarkerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* OmegaT - Computer Assisted Translation (CAT) tool
* with fuzzy matching, translation memory, keyword search,
* glossaries, and translation leveraging into updated projects.
*
* Copyright (C) 2024 Hiroshi Miura.
* Home page: https://www.omegat.org/
* Support center: https://omegat.org/support
*
* This file is part of OmegaT.
*
* OmegaT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OmegaT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.omegat.gui.editor.mark;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import org.omegat.core.Core;
import org.omegat.core.TestCoreInitializer;
import org.omegat.core.data.DataUtils;
import org.omegat.core.data.EntryKey;
import org.omegat.core.data.NotLoadedProject;
import org.omegat.core.data.ProjectProperties;
import org.omegat.core.data.ProjectTMX;
import org.omegat.core.data.SourceTextEntry;
import org.omegat.core.data.TMXEntry;
import org.omegat.core.matching.NearString;
import org.omegat.core.segmentation.SRX;
import org.omegat.core.segmentation.Segmenter;
import org.omegat.util.Language;

public class ComesFromMTMarkerTest extends MarkerTestBase {

private ProjectTMX projectTMX;
private Path tmroot;
private Path project;

@Before
public void preUp() throws Exception {
tmroot = Paths.get("test/data/tmx/");
project = tmroot.resolve("mt/mt1.tmx"); // should under 'mt'
TestCoreInitializer.initEditor(editor);
Core.setSegmenter(new Segmenter(SRX.getDefault()));
projectTMX = new ProjectTMX(new Language("en"), new Language("fr"), true,
project.toFile(), null);
Core.setProject(new NotLoadedProject() {
@Override
public boolean isProjectLoaded() {
return true;
}

@Override
public ProjectProperties getProjectProperties() {
return new ProjectProperties() {
@Override
public Language getSourceLanguage() {
return new Language("en");
}

@Override
public Language getTargetLanguage() {
return new Language("fr");
}

@Override
public String getTMRoot() {
return tmroot.toString();
}

};
}

@Override
public TMXEntry getTranslationInfo(SourceTextEntry ste) {
if (ste == null || projectTMX == null) {
return EMPTY_TRANSLATION;
}
TMXEntry r = projectTMX.getMultipleTranslation(ste.getKey());
if (r == null) {
r = projectTMX.getDefaultTranslation(ste.getSrcText());
}
if (r == null) {
r = EMPTY_TRANSLATION;
}
return r;
}

});
}

@Test
public void testMarkersDisabled() throws Exception {
IMarker marker = new ComesFromMTMarker();
assertThat(marker.getMarksForEntry(null, null, null, true))
.describedAs("marker should return null when ste, sourceText and translationText is null")
.isNull();
}

@Test
public void testMarkersNotActive() throws Exception {
IMarker marker = new ComesFromMTMarker();
final String sourceText = "source";
final String targetText = "target";
EntryKey key = new EntryKey("file", sourceText, "id", "prev", "next", "path");
SourceTextEntry ste = new SourceTextEntry(key, 1, new String[0], sourceText, Collections.emptyList());
assertThat(marker.getMarksForEntry(ste, sourceText, targetText, false))
.describedAs("marker should return null when ste is not active")
.isNull();
}

@Test
public void testMarkersMT() {
ComesFromMTMarker marker = new ComesFromMTMarker();
final String sourceText = "source";
final String targetText = "target";
EntryKey key = new EntryKey("file", sourceText, "id", "prev", "next", "path");
SourceTextEntry ste = new SourceTextEntry(key, 1, new String[0], sourceText, Collections.emptyList());
marker.setMark(ste, targetText);
List<Mark> result = marker.getMarksForEntry(ste, sourceText, targetText, true);
assertNotNull(result);
assertEquals(1, result.size());
assertEquals(0, result.get(0).startOffset);
assertEquals(6, result.get(0).endOffset);
assertEquals("TRANSLATION", result.get(0).entryPart.toString());
}

@Test
public void testNearString() {
final String sourceText = "source";
final String targetText = "target";
final String user = "translator";
final int score = 75;
final byte[] nearData = null;
final long date = 10000L;
EntryKey key = new EntryKey("file", sourceText, "id", "prev", "next", "path");
NearString near = new NearString(key, sourceText, targetText, NearString.MATCH_SOURCE.TM, false,
score, score, score, nearData, project.toString(), user, date, user, date, Collections.emptyList());
assertThat(DataUtils.isFromMTMemory(near)).isTrue();
}
}
Loading