use of gen.core.tbx.LangSet in project omegat by omegat-org.
the class GlossaryReaderTBX method readMartif.
public static List<GlossaryEntry> readMartif(final Martif tbx, boolean priorityGlossary, String origin) throws Exception {
if (tbx.getText() == null) {
return Collections.emptyList();
}
String sLang = Core.getProject().getProjectProperties().getSourceLanguage().getLanguageCode();
String tLang = Core.getProject().getProjectProperties().getTargetLanguage().getLanguageCode();
StringBuilder note = new StringBuilder();
StringBuilder descTerm = new StringBuilder();
StringBuilder descTig = new StringBuilder();
List<GlossaryEntry> result = new ArrayList<GlossaryEntry>();
List<String> sTerms = new ArrayList<String>();
List<String> tTerms = new ArrayList<String>();
for (TermEntry te : tbx.getText().getBody().getTermEntry()) {
note.setLength(0);
descTerm.setLength(0);
descTig.setLength(0);
appendDescOrNote(te.getDescripOrDescripGrpOrAdmin(), descTerm);
for (LangSet ls : te.getLangSet()) {
Language termLanguage = new Language(ls.getLang());
// We use only the language code
String lang = termLanguage.getLanguageCode();
appendDescOrNote(ls.getDescripOrDescripGrpOrAdmin(), descTig);
for (Object o : ls.getTigOrNtig()) {
if (o instanceof Tig) {
Tig t = (Tig) o;
if (sLang.equalsIgnoreCase(lang)) {
sTerms.add(readContent(t.getTerm().getContent()));
} else if (tLang.equalsIgnoreCase(lang)) {
tTerms.add(readContent(t.getTerm().getContent()));
appendDescOrNote(t.getTermNote(), note);
}
appendDescOrNote(t.getDescripOrDescripGrpOrAdmin(), descTig);
} else if (o instanceof Ntig) {
Ntig n = (Ntig) o;
if (sLang.equalsIgnoreCase(lang)) {
sTerms.add(readContent(n.getTermGrp().getTerm().getContent()));
} else if (tLang.equalsIgnoreCase(lang)) {
tTerms.add(readContent(n.getTermGrp().getTerm().getContent()));
appendDescOrNote(n.getTermGrp().getTermNoteOrTermNoteGrp(), note);
}
appendDescOrNote(n.getDescripOrDescripGrpOrAdmin(), descTig);
}
}
}
StringBuilder comment = new StringBuilder();
appendLine(comment, descTerm.toString());
appendLine(comment, descTig.toString());
appendLine(comment, note.toString());
for (String s : sTerms) {
boolean addedForLang = false;
for (String t : tTerms) {
result.add(new GlossaryEntry(s, t, comment.toString(), priorityGlossary, origin));
addedForLang = true;
}
if (!addedForLang) {
// An entry is created just to get the definition
result.add(new GlossaryEntry(s, "", comment.toString(), priorityGlossary, origin));
}
}
sTerms.clear();
tTerms.clear();
}
return result;
}