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

feat: filter(po): plural as comment in japanese target #1165

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/org/omegat/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2257,6 +2257,7 @@ POFILTER_TRANSLATOR_COMMENTS=Translator comments:
POFILTER_EXTRACTED_COMMENTS=Extracted comments:
POFILTER_REFERENCES=References:
POFILTER_PLURAL_FORM_COMMENT=Translate this plural as a plural form #{0}.
POFILTER_SINGULAR_COMMENT=Corresponding plural source:

# HTML-Filter
HTMLFILTER_TAG=Tag:
Expand Down
43 changes: 26 additions & 17 deletions src/org/omegat/filters2/po/PoFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
2008 Martin Fleurke
2009 Alex Buloichik
2011 Didier Briel
2013-1014 Alex Buloichik, Enrique Estevez
2013-2014 Alex Buloichik, Enrique Estevez
2017 Didier Briel
2023 Hiroshi Miura
2023-2024 Hiroshi Miura
Home page: https://www.omegat.org/
Support center: https://omegat.org/support

Expand Down Expand Up @@ -313,7 +313,10 @@ enum MODE {
}

private StringBuilder[] sources, targets;
private StringBuilder translatorComments, extractedComments, references, sourceFuzzyTrue;
private StringBuilder translatorComments;
private StringBuilder extractedComments;
private StringBuilder references;
private StringBuilder sourceFuzzyTrue;
private int plurals = 2;
private String path;
private boolean nowrap, fuzzy, fuzzyTrue;
Expand Down Expand Up @@ -610,33 +613,39 @@ protected void eol(String s) throws IOException {

protected void parseOrAlign(int pair) {
String pathSuffix;
String s;
String c = "";
String source;
StringBuilder sb = new StringBuilder();
if (pair > 0) {
s = unescape(sources[1].toString());
source = unescape(sources[1].toString());
pathSuffix = "[" + pair + "]";
c += StringUtil.format(OStrings.getString("POFILTER_PLURAL_FORM_COMMENT"), pair) + "\n";
sb.append(StringUtil.format(OStrings.getString("POFILTER_PLURAL_FORM_COMMENT"), pair)).append("\n");
} else {
s = unescape(sources[pair].toString());
source = unescape(sources[0].toString());
pathSuffix = "";
String s1 = unescape(sources[1].toString());
if (!StringUtil.isEmpty(s1)) {
sb.append(OStrings.getString("POFILTER_SINGULAR_COMMENT")).append("\n").append(s1).append("\n\n");
}
}
String t = unescape(targets[pair].toString());
String translate = unescape(targets[pair].toString());

if (translatorComments.length() > 0) {
c += OStrings.getString("POFILTER_TRANSLATOR_COMMENTS") + "\n"
+ unescape(translatorComments.toString() + "\n");
sb.append(OStrings.getString("POFILTER_TRANSLATOR_COMMENTS")).append("\n").append(unescape(
translatorComments.toString())).append("\n");
}
if (extractedComments.length() > 0) {
c += OStrings.getString("POFILTER_EXTRACTED_COMMENTS") + "\n"
+ unescape(extractedComments.toString() + "\n");
sb.append(OStrings.getString("POFILTER_EXTRACTED_COMMENTS")).append("\n").append(unescape(
extractedComments.toString())).append("\n");
}
if (references.length() > 0) {
c += OStrings.getString("POFILTER_REFERENCES") + "\n" + unescape(references.toString() + "\n");
sb.append(OStrings.getString("POFILTER_REFERENCES")).append("\n").append(unescape(references
.toString())).append("\n");
}
if (c.isEmpty()) {
c = null;
String comments = sb.toString();
if (comments.isEmpty()) {
comments = null;
}
parseOrAlign(s, t, c, pathSuffix);
parseOrAlign(source, translate, comments, pathSuffix);
}

/**
Expand Down
21 changes: 12 additions & 9 deletions test/src/org/omegat/filters/POFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ public void testParse() throws Exception {

parse2(new PoFilter(), "test/data/filters/po/file-POFilter-be.po", data, tmx);

assertEquals(data.get("non-fuzzy"), "non-fuzzy translation");
assertEquals(tmx.get("[PO-fuzzy] fuzzy"), "fuzzy translation");
assertEquals(tmx.get("[PO-fuzzy] Delete Account"), "Supprimer le compte");
assertEquals(tmx.get("[PO-fuzzy] Delete Accounts"), "Supprimer des comptes");
assertEquals("non-fuzzy translation", data.get("non-fuzzy"));
assertEquals("fuzzy translation", tmx.get("[PO-fuzzy] fuzzy"));
assertEquals("Supprimer le compte", tmx.get("[PO-fuzzy] Delete Account"));
assertEquals("Supprimer des comptes", tmx.get("[PO-fuzzy] Delete Accounts"));
}

@Test
public void testLoad() throws Exception {
String f = "test/data/filters/po/file-POFilter-multiple.po";
Map<String, String> options = new TreeMap<String, String>();
Map<String, String> options = new TreeMap<>();
options.put("skipHeader", "true");
TestFileInfo fi = loadSourceFiles(new PoFilter(), f, options);

Expand All @@ -76,7 +76,8 @@ public void testLoad() throws Exception {
checkMulti("source3", null, "", null, null, null);
checkMulti("source1", null, "", null, null, null);
checkMulti("source1", null, "other context", null, null, null);
checkMulti("source4", null, "one more context", null, null, null);
checkMulti("source4", null, "one more context", null, null,
OStrings.getString("POFILTER_SINGULAR_COMMENT") + "\nsource4\n\n");
checkMulti("source4", null, "one more context[1]", null, null,
StringUtil.format(OStrings.getString("POFILTER_PLURAL_FORM_COMMENT"), 1) + "\n");
checkMulti("source4", null, "one more context[2]", null, null,
Expand All @@ -103,7 +104,7 @@ public void testLoad() throws Exception {
public void testLoadMonolingual() throws Exception {
String f = "test/data/filters/po/file-POFilter-Monolingual.po";
PoFilter filter = new PoFilter();
Map<String, String> options = new TreeMap<String, String>();
Map<String, String> options = new TreeMap<>();
options.put(PoFilter.OPTION_FORMAT_MONOLINGUAL, "true");
List<ParsedEntry> parsed = parse3(filter, f, options);
assertEquals(2, parsed.size());
Expand Down Expand Up @@ -138,7 +139,8 @@ public void testLoad2() throws Exception {
TestFileInfo fi = loadSourceFiles(new PoFilter(), f, options);

checkMultiStart(fi, f);
checkMulti("Changed %d key", null, "", null, null, null);
checkMulti("Changed %d key", null, "", null, null,
OStrings.getString("POFILTER_SINGULAR_COMMENT") + "\n\nChanged %d keys\n\n");
checkMulti("Changed %d keys", null, "[1]", null, null,
OStrings.getString("POFILTER_PLURAL_FORM_COMMENT", 1) + "\n");
checkMulti("Changed %d keys", null, "[2]", null, null,
Expand All @@ -159,7 +161,8 @@ public void testLoad3() throws Exception {
TestFileInfo fi = loadSourceFiles(new PoFilter(), f, options);

checkMultiStart(fi, f);
checkMulti("Changed %d key", null, "", null, null, null);
checkMulti("Changed %d key", null, "", null, null,
OStrings.getString("POFILTER_SINGULAR_COMMENT") + "\n\nChanged %d keys\n\n");
checkMulti("Changed %d keys", null, "[1]", null, null,
OStrings.getString("POFILTER_PLURAL_FORM_COMMENT", 1) + "\n");
checkMulti("Changed %d keys", null, "[2]", null, null,
Expand Down
Loading