Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
hylstonnb committed Aug 18, 2023
1 parent b1dc2a5 commit 8e904a3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class JSONFilter extends net.sf.okapi.filters.json.JSONFilter {
*/
boolean noteKeepOrReplace = false;

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

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

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

xliffNoteAnnotation.add(xliffNote);
noteAnnotation.add(note);
}

void extractNoteIfMatch(String value) {
Expand All @@ -163,7 +163,7 @@ void extractNoteIfMatch(String value) {

if (m.matches()) {
logger.debug("key matches noteKeyPattern, add the value as note");
addXliffNote(value);
addNote(value);
}
}
}
Expand All @@ -172,10 +172,10 @@ void processComment() {
if (comment != null) {
ITextUnit textUnit = getEventTextUnit();
if (textUnit != null) {
String xliffNote = comment.replace("//", "").trim();
addXliffNote(xliffNote);
textUnit.setAnnotation(xliffNoteAnnotation);
xliffNoteAnnotation = null;
String note = comment.replace("//", "").trim();
addNote(note);
textUnit.setAnnotation(noteAnnotation);
noteAnnotation = null;
}
comment = null;
}
Expand All @@ -184,14 +184,14 @@ void processComment() {
@Override
public void handleObjectEnd() {

if (xliffNoteAnnotation != null || usagesAnnotation != null) {
if (noteAnnotation != null || usagesAnnotation != null) {

ITextUnit textUnit = getEventTextUnit();

if (textUnit != null) {
if (xliffNoteAnnotation != null) {
if (noteAnnotation != null) {
logger.debug("Set note on text unit with name: {}", textUnit.getName());
textUnit.setAnnotation(xliffNoteAnnotation);
textUnit.setAnnotation(noteAnnotation);
}

if (usagesAnnotation != null) {
Expand All @@ -203,10 +203,9 @@ public void handleObjectEnd() {
}
}

logger.debug(
"Reset the xliffNoteAnnotation and Usage Annotation if not using keepOrReplace option");
logger.debug("Reset the noteAnnotation and Usage Annotation if not using keepOrReplace option");
if (!noteKeepOrReplace) {
xliffNoteAnnotation = null;
noteAnnotation = null;
}

if (!usagesKeepOrReplace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,12 +603,12 @@ public void writeTextUnit(ITextUnit tu, String phaseName) {

// Notes
if (tu.hasProperty(NoteAnnotation.LOC_NOTE)) {
writer.writeStartElement(NoteAnnotation.LOC_NOTE);
writer.writeStartElement("note");
writer.writeString(tu.getProperty(NoteAnnotation.LOC_NOTE).getValue());
writer.writeEndElementLineBreak(); // note
}
if (tu.hasProperty(NoteAnnotation.TRANS_NOTE)) {
writer.writeStartElement(NoteAnnotation.LOC_NOTE);
writer.writeStartElement("note");
writer.writeAttributeString("from", "translator");
writer.writeString(tu.getProperty(NoteAnnotation.TRANS_NOTE).getValue());
writer.writeEndElementLineBreak(); // note
Expand All @@ -619,7 +619,7 @@ public void writeTextUnit(ITextUnit tu, String phaseName) {

if (annotation != null) {
Note note = annotation.getNote(0);
writer.writeStartElement(NoteAnnotation.LOC_NOTE);
writer.writeStartElement("note");
writer.writeString(note.getNoteText());
writer.writeEndElementLineBreak();
}
Expand Down

0 comments on commit 8e904a3

Please sign in to comment.