diff --git a/src/org/omegat/Bundle.properties b/src/org/omegat/Bundle.properties index 136ce39815..0d84df08e6 100644 --- a/src/org/omegat/Bundle.properties +++ b/src/org/omegat/Bundle.properties @@ -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: diff --git a/src/org/omegat/filters2/po/PoFilter.java b/src/org/omegat/filters2/po/PoFilter.java index 85ff8183fc..b40daccff1 100644 --- a/src/org/omegat/filters2/po/PoFilter.java +++ b/src/org/omegat/filters2/po/PoFilter.java @@ -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 @@ -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; @@ -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); } /** diff --git a/test/src/org/omegat/filters/POFilterTest.java b/test/src/org/omegat/filters/POFilterTest.java index e3f9007107..2a3ffebeed 100644 --- a/test/src/org/omegat/filters/POFilterTest.java +++ b/test/src/org/omegat/filters/POFilterTest.java @@ -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 options = new TreeMap(); + Map options = new TreeMap<>(); options.put("skipHeader", "true"); TestFileInfo fi = loadSourceFiles(new PoFilter(), f, options); @@ -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, @@ -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 options = new TreeMap(); + Map options = new TreeMap<>(); options.put(PoFilter.OPTION_FORMAT_MONOLINGUAL, "true"); List parsed = parse3(filter, f, options); assertEquals(2, parsed.size()); @@ -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, @@ -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,