Skip to content

Commit

Permalink
okapi dependency update from V. 0.36 to 1.45.0 which is the latest
Browse files Browse the repository at this point in the history
  • Loading branch information
hylstonnb committed Aug 14, 2023
1 parent 92fadd6 commit 0b34ce9
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.box.l10n.mojito.okapi;

import java.util.Objects;
import net.sf.okapi.common.annotation.XLIFFNoteAnnotation;
import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.resource.ITextUnit;
import net.sf.okapi.common.resource.Property;
import net.sf.okapi.common.resource.TextContainer;
Expand Down Expand Up @@ -30,12 +30,12 @@ public String getNote(ITextUnit textUnit) {

if (textUnit != null) {

XLIFFNoteAnnotation xliffNoteAnnotation = textUnit.getAnnotation(XLIFFNoteAnnotation.class);
NoteAnnotation noteAnnotation = textUnit.getAnnotation(NoteAnnotation.class);

if (xliffNoteAnnotation == null) {
note = Objects.toString(textUnit.getProperty(Property.NOTE), null);
if (noteAnnotation == null) {
note = Objects.toString(textUnit.getProperty(NoteAnnotation.LOC_NOTE), null);
} else {
note = xliffNoteAnnotation.getNote(0).getNoteText();
note = noteAnnotation.getNote(0).getNoteText();
}
}

Expand All @@ -51,7 +51,7 @@ public String getNote(ITextUnit textUnit) {
public void setNote(ITextUnit textUnit, String note) {

if (textUnit != null) {
textUnit.setProperty(new Property(Property.NOTE, note));
textUnit.setProperty(new Property(NoteAnnotation.LOC_NOTE, note));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import net.sf.okapi.common.Event;
import net.sf.okapi.common.IResource;
import net.sf.okapi.common.LocaleId;
import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.filters.FilterConfiguration;
import net.sf.okapi.common.resource.ITextUnit;
import net.sf.okapi.common.resource.Property;
import net.sf.okapi.common.resource.RawDocument;
import net.sf.okapi.common.resource.TextUnit;
import net.sf.okapi.common.skeleton.GenericSkeleton;
Expand Down Expand Up @@ -198,7 +198,7 @@ protected void extractNoteFromXMLCommentInSkeletonIfNone(TextUnit textUnit) {

String skeleton = textUnit.getSkeleton().toString();

if (textUnit.getProperty(Property.NOTE) == null) {
if (textUnit.getProperty(NoteAnnotation.LOC_NOTE) == null) {
String note = getNoteFromXMLCommentsInSkeleton(skeleton);
if (note != null) {
textUnitUtils.setNote(textUnit, note);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.box.l10n.mojito.okapi.filters;

import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.resource.ITextUnit;
import net.sf.okapi.common.resource.Property;
import net.sf.okapi.filters.table.csv.CommaSeparatedValuesFilter;
Expand Down Expand Up @@ -45,7 +46,7 @@ public CSVFilter() {
@Override
protected boolean processTU(ITextUnit textUnit) {

Property note = textUnit.getProperty(Property.NOTE);
Property note = textUnit.getProperty(NoteAnnotation.LOC_NOTE);
if (note != null) {
String comments = note.toString();
char quote = "\"".charAt(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.sf.okapi.common.IParameters;
import net.sf.okapi.common.MimeTypeMapper;
import net.sf.okapi.common.Util;
import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.encoder.EncoderManager;
import net.sf.okapi.common.exceptions.OkapiIOException;
import net.sf.okapi.common.exceptions.OkapiUnsupportedEncodingException;
Expand Down Expand Up @@ -268,7 +269,7 @@ private TextUnit readTextUnit() {
skel.append(data.toString());
textUnit = processKeyValueLine();
if (textUnit != null && comment != null) {
textUnit.setProperty(new Property(Property.NOTE, comment, true));
textUnit.setProperty(new Property(NoteAnnotation.LOC_NOTE, comment, true));
}
break;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sf.okapi.common.Event;
import net.sf.okapi.common.annotation.XLIFFNote;
import net.sf.okapi.common.annotation.XLIFFNoteAnnotation;
import net.sf.okapi.common.annotation.Note;
import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.filters.FilterConfiguration;
import net.sf.okapi.common.resource.ITextUnit;
import net.sf.okapi.common.resource.RawDocument;
Expand Down Expand Up @@ -44,7 +44,7 @@ public class JSONFilter extends net.sf.okapi.filters.json.JSONFilter {
*/
boolean noteKeepOrReplace = false;

XLIFFNoteAnnotation xliffNoteAnnotation;
NoteAnnotation xliffNoteAnnotation;
UsagesAnnotation usagesAnnotation;
String currentKeyName;
String comment = null;
Expand Down Expand Up @@ -145,13 +145,13 @@ void extractUsageIfMatch(String value) {
}

void addXliffNote(String value) {
XLIFFNote xliffNote = new XLIFFNote(value);
Note xliffNote = new Note(value);
xliffNote.setFrom(currentKeyName);
xliffNote.setAnnotates(XLIFFNote.Annotates.SOURCE);
xliffNote.setAnnotates(Note.Annotates.SOURCE);

if (xliffNoteAnnotation == null || noteKeepOrReplace) {
logger.debug("create the xliff note annotation");
xliffNoteAnnotation = new XLIFFNoteAnnotation();
xliffNoteAnnotation = new NoteAnnotation();
}

xliffNoteAnnotation.add(xliffNote);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sf.okapi.common.*;
import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.filters.FilterConfiguration;
import net.sf.okapi.common.resource.*;
import net.sf.okapi.common.skeleton.GenericSkeleton;
Expand Down Expand Up @@ -121,7 +122,7 @@ protected void extractNoteFromXMLCommentInSkeletonIfNone(TextUnit textUnit) {

String skeleton = textUnit.getSkeleton().toString();

if (textUnit.getProperty(Property.NOTE) == null) {
if (textUnit.getProperty(NoteAnnotation.LOC_NOTE) == null) {
String note = getNoteFromXMLCommentsInSkeleton(skeleton);
if (note != null) {
comment = note;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public Event handleEvent(Event event) {
switch (event.getEventType()) {
case START_DOCUMENT:
handleStartDocument(event);
return Event.NOOP_EVENT;
return Event.createNoopEvent();

case END_DOCUMENT:
return processEndDocument(event);
Expand All @@ -95,7 +95,7 @@ public Event handleEvent(Event event) {
case TEXT_UNIT:
// handle all the events between START_DOCUMENT and END_DOCUMENT
filterWriter.handleEvent(event);
return Event.NOOP_EVENT;
return Event.createNoopEvent();
}

// Else, just return the event
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<maven.compiler.version>3.5.1</maven.compiler.version>
<maven.deploy.version>2.8.2</maven.deploy.version>
<maven.release.version>2.5.3</maven.release.version>
<okapi.version>0.36</okapi.version>
<okapi.version>1.45.0</okapi.version>
<guava.version>29.0-jre</guava.version>
<hibernate.joda-time.version>1.4</hibernate.joda-time.version>
<usertype.core.version>6.0.1.GA</usertype.core.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.box.l10n.mojito.json.ObjectMapper;
import com.box.l10n.mojito.service.tm.ImportExportNote;
import java.io.IOException;
import net.sf.okapi.common.annotation.XLIFFNote;
import net.sf.okapi.common.annotation.XLIFFNoteAnnotation;
import net.sf.okapi.common.annotation.Note;
import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.resource.ITextUnit;
import net.sf.okapi.common.resource.Property;
import net.sf.okapi.common.resource.TextUnit;
Expand Down Expand Up @@ -33,7 +33,7 @@ public class ImportExportTextUnitUtils {
public void setNote(ITextUnit textUnit, String note) {

if (textUnit != null) {
textUnit.setProperty(new Property(Property.NOTE, note));
textUnit.setProperty(new Property(NoteAnnotation.LOC_NOTE, note));
}
}

Expand Down Expand Up @@ -76,15 +76,15 @@ public void setImportExportNote(ITextUnit textUnit, ImportExportNote importExpor

String importExportNoteStr = objectMapper.writeValueAsStringUnchecked(importExportNote);

XLIFFNoteAnnotation xliffNoteAnnotation = textUnit.getAnnotation(XLIFFNoteAnnotation.class);
NoteAnnotation noteAnnotation = textUnit.getAnnotation(NoteAnnotation.class);

if (xliffNoteAnnotation == null) {
xliffNoteAnnotation = new XLIFFNoteAnnotation();
textUnit.setAnnotation(xliffNoteAnnotation);
if (noteAnnotation == null) {
noteAnnotation = new NoteAnnotation();
textUnit.setAnnotation(noteAnnotation);
} else {
setNote(textUnit, importExportNoteStr);
}

xliffNoteAnnotation.add(new XLIFFNote(importExportNoteStr));
noteAnnotation.add(new Note(importExportNoteStr));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected Event handleTextUnit(Event event) {
if (androidEvent == null) {
switch (getRemoveUntranslatedStrategyFromAnnotation()) {
case NOOP_EVENT:
event = Event.NOOP_EVENT;
event = Event.createNoopEvent();
break;
case PLACEHOLDER_AND_POST_PROCESSING:
logger.debug("Set untranslated placeholder for text unit with name: {}", name);
Expand Down
22 changes: 11 additions & 11 deletions webapp/src/main/java/com/box/l10n/mojito/okapi/XLIFFWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import net.sf.okapi.common.annotation.GenericAnnotations;
import net.sf.okapi.common.annotation.ITSLQIAnnotations;
import net.sf.okapi.common.annotation.ITSProvenanceAnnotations;
import net.sf.okapi.common.annotation.Note;
import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.annotation.TermsAnnotation;
import net.sf.okapi.common.annotation.XLIFFNote;
import net.sf.okapi.common.annotation.XLIFFNoteAnnotation;
import net.sf.okapi.common.encoder.EncoderManager;
import net.sf.okapi.common.filterwriter.IFilterWriter;
import net.sf.okapi.common.filterwriter.ITSContent;
Expand Down Expand Up @@ -602,24 +602,24 @@ public void writeTextUnit(ITextUnit tu, String phaseName) {
}

// Notes
if (tu.hasProperty(Property.NOTE)) {
writer.writeStartElement("note");
writer.writeString(tu.getProperty(Property.NOTE).getValue());
if (tu.hasProperty(NoteAnnotation.LOC_NOTE)) {
writer.writeStartElement(NoteAnnotation.LOC_NOTE);
writer.writeString(tu.getProperty(NoteAnnotation.LOC_NOTE).getValue());
writer.writeEndElementLineBreak(); // note
}
if (tu.hasProperty(Property.TRANSNOTE)) {
writer.writeStartElement("note");
if (tu.hasProperty(NoteAnnotation.TRANS_NOTE)) {
writer.writeStartElement(NoteAnnotation.LOC_NOTE);
writer.writeAttributeString("from", "translator");
writer.writeString(tu.getProperty(Property.TRANSNOTE).getValue());
writer.writeString(tu.getProperty(NoteAnnotation.TRANS_NOTE).getValue());
writer.writeEndElementLineBreak(); // note
}

// CHANGES FOR MOJITO
XLIFFNoteAnnotation annotation = tu.getAnnotation(XLIFFNoteAnnotation.class);
NoteAnnotation annotation = tu.getAnnotation(NoteAnnotation.class);

if (annotation != null) {
XLIFFNote note = annotation.getNote(0);
writer.writeStartElement("note");
Note note = annotation.getNote(0);
writer.writeStartElement(NoteAnnotation.LOC_NOTE);
writer.writeString(note.getNoteText());
writer.writeEndElementLineBreak();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public void disableAllChecks() {
setCheckXliffSchema(false);
setCheckPatterns(false);
setCheckWithLT(false);
setTranslateLTMsg(false);
setLtBilingualMode(false);
setDoubledWord(false);
setCorruptedCharacters(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import net.sf.okapi.common.EventType;
import net.sf.okapi.common.IParameters;
import net.sf.okapi.common.LocaleId;
import net.sf.okapi.common.annotation.XLIFFNote;
import net.sf.okapi.common.annotation.XLIFFNoteAnnotation;
import net.sf.okapi.common.annotation.Note;
import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.encoder.EncoderManager;
import net.sf.okapi.common.filters.FilterConfiguration;
import net.sf.okapi.common.filters.IFilter;
Expand Down Expand Up @@ -235,10 +235,10 @@ private TextUnit getNextTextUnit() throws NoSuchElementException {
if (textUnitDTO.getComment() != null) {
importExportTextUnitUtils.setNote(textUnit, textUnitDTO.getComment());

XLIFFNoteAnnotation xliffNoteAnnotation = new XLIFFNoteAnnotation();
XLIFFNote xliffNote = new XLIFFNote(textUnitDTO.getComment());
xliffNoteAnnotation.add(xliffNote);
textUnit.getSource().setAnnotation(xliffNoteAnnotation);
NoteAnnotation noteAnnotation = new NoteAnnotation();
Note xliffNote = new Note(textUnitDTO.getComment());
noteAnnotation.add(xliffNote);
textUnit.getSource().setAnnotation(noteAnnotation);
}

return textUnit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.Objects;
import net.sf.okapi.common.LocaleId;
import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.resource.Property;
import net.sf.okapi.common.resource.TextContainer;
import net.sf.okapi.common.resource.TextUnit;
Expand Down Expand Up @@ -51,7 +52,7 @@ public TextUnit createTextUnit(
textUnit.setName(name);

if (note != null) {
textUnit.setSourceProperty(new Property(Property.NOTE, note));
textUnit.setSourceProperty(new Property(NoteAnnotation.LOC_NOTE, note));
}

if (target != null && targetBcp47Tag != null) {
Expand Down Expand Up @@ -130,7 +131,7 @@ private String generateXliff(List<TextUnit> textUnits, String targetBcp47Tag) {
">" + textUnit.getTarget(LocaleId.fromBCP47(targetBcp47Tag)).toString() + "</target>\n";
}

String note = Objects.toString(textUnit.getSourceProperty(Property.NOTE), null);
String note = Objects.toString(textUnit.getSourceProperty(NoteAnnotation.LOC_NOTE), null);
if (note != null) {
if (!isTargetXliff) {
// Okapi does not indent code properly...
Expand Down

0 comments on commit 0b34ce9

Please sign in to comment.