-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoto_next_ta_note.groovy
108 lines (99 loc) · 3.12 KB
/
goto_next_ta_note.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*:name = GoTo - T&A note / next :description = Jumps to the next segment which has a T&A note
*
* @author: Kos Ivantsov
* @date: 2024-08-19
* @version: 0.1
*/
import org.omegat.core.data.SourceTextEntry
import org.omegat.core.data.TMXEntry
import org.omegat.core.data.ProjectTMX
import org.omegat.core.data.EntryKey
prop = project.projectProperties
exit = false
if (!prop) {
final def title = 'Next T&A note'
final def msg = 'Please try again after you open a project.'
showMessageDialog null, msg, title, INFORMATION_MESSAGE
exit = true
return
}
checkOrphanedCallback = new ProjectTMX.CheckOrphanedCallback() {
boolean existSourceInProject(String src) {
return existSource.contains(src)
}
boolean existEntryInProject(EntryKey key) {
return existKeys.contains(key)
}
}
def loadTmxFile(File tmxFile) {
notesTmx = new ProjectTMX(srcLang, traLang,
Core.getProject().getProjectProperties().isSentenceSegmentingEnabled(), tmxFile, checkOrphanedCallback)
}
def getComment(SourceTextEntry newEntry) {
if (notesTmx == null) {
return null
}
TMXEntry te = notesTmx.getMultipleTranslation(newEntry.getKey())
if (te == null) {
te = notesTmx.getDefaultTranslation(newEntry.getSrcText())
}
if (te != null) {
if (te.translation == null)
try {
if ((! this.srcLang.equals(prop.getSourceLanguage()))
|| (! this.traLang.equals(prop.getTargetLanguage()))) {
return null
}
checkTmxFileLanguages()
loadTmxFile(tmxFile)
return getComment(newEntry)
} catch (Exception ex) {
ex.printStackTrace()
}
return "T&A note: " + te.translation
}
return null
}
lastSegmentNumber = project.allEntries.size()
jump = false
def gui() {
File dir = new File(prop.getProjectRoot() + "/notes");
if (dir.exists()) {
list = dir.listFiles().findAll { it.isFile() && it.name.toLowerCase().endsWith('.tmx') }
if (list.size() == 0) {
console.println("Extra notes : /notes directory exists but contains no files")
exit = true
} else {
srcLang = prop.getSourceLanguage()
traLang = prop.getTargetLanguage()
loadTmxFile(tmxFile = list[0]);
}
} else {
exit = true
}
if (exit) {
return
}
ste = editor.getCurrentEntry()
currentSegmentNumber = startingSegmentNumber = ste.entryNum()
while (!jump) {
nextSegmentNumber = currentSegmentNumber == lastSegmentNumber ? 1 : currentSegmentNumber + 1
stn = project.allEntries[nextSegmentNumber - 1]
info = project.getTranslationInfo(stn)
src = stn.getSrcText()
comment = getComment(stn)
if (nextSegmentNumber == startingSegmentNumber) {
return
}
if (comment) {
jump = true
console.println(comment)
editor.gotoEntry(nextSegmentNumber)
return
} else {
jump = false
currentSegmentNumber = nextSegmentNumber
}
}
}
return