Repository: flashcode/msgcheck (language: python)

Issue:
Punctuation in far east languages
Hi @flashcode,

it's been a while. Still a waving fan of this package. That being said, I am currently translating things into Japanese and Simplified Chinese. In those languages it is common to use a different character. E.G. in Japanese you would use a [。](https://en.wikipedia.org/wiki/Japanese_punctuation).

Would you be interested in a patch adding support for punctuation for individual locales?

Best,
Joe


Discussion / hints:
Hi Joe,

Sure your contributions are welcome!

I use msgcheck for WeeChat (among others) where there are Japanese translations, so handling the punctuation for these languages would be nice.

Thank you.

Fix patch:
diff --git a/msgcheck/po.py b/msgcheck/po.py
index cea2a50..ba84b7d 100644
--- a/msgcheck/po.py
+++ b/msgcheck/po.py
@@ -180,8 +180,8 @@ def check_punct(self, language):
                 continue
             puncts = [(':', ':'), (';', ';'), (',', ','), ('...', '...')]
             # special symbols in some languages
-            if language.startswith('ja'):
-                puncts.append(('.', '。'))
+            if language[:2] in ['ja', 'zh']:
+                puncts.append(('.', u'。'))
             else:
                 puncts.append(('.', '.'))
             for punctid, punctstr in puncts:
@@ -195,15 +195,15 @@ def check_punct(self, language):
                     break
                 if match_id and not match_str:
                     errors.append(
-                        PoReport('end punctuation: "{0}" in string, '
-                                 '"{1}" not in translation'
+                        PoReport(u'end punctuation: "{0}" in string, '
+                                 u'"{1}" not in translation'
                                  ''.format(punctid, punctstr),
                                  'punct', self.filename, self.line, mid, mstr))
                     break
                 if not match_id and match_str:
                     errors.append(
-                        PoReport('end punctuation: "{0}" in translation, '
-                                 '"{1}" not in string'
+                        PoReport(u'end punctuation: "{0}" in translation, '
+                                 u'"{1}" not in string'
                                  ''.format(punctstr, punctid),
                                  'punct', self.filename, self.line, mid, mstr))
                     break


Test patch:
diff --git a/tests/test_msgcheck.py b/tests/test_msgcheck.py
index 0ccde01..05c3bef 100644
--- a/tests/test_msgcheck.py
+++ b/tests/test_msgcheck.py
@@ -24,7 +24,7 @@
 import pytest
 
 from msgcheck.msgcheck import msgcheck_version
-from msgcheck.po import PoFile, PoCheck
+from msgcheck.po import PoFile, PoCheck, PoMessage
 from msgcheck.utils import replace_formatters
 
 
@@ -347,3 +347,30 @@ def test_spelling_bad_pwl():
     with pytest.raises(IOError):
         pwl_files = [local_path('pwl_does_not_exist.txt')]
         po_check.set_spelling_options('str', None, pwl_files)
+
+
+@pytest.mark.parametrize('language, msgid, msgstr, error_message', [
+    ('ja', 'Should not raise an error.', u'エラーが発生しないようにしてください。', ''),
+    ('ja', 'Should raise an error', u'エラーを発生させる必要があります。',
+     u'end punctuation: "。" in translation, "." not in string'),
+    ('ja', 'Should raise an error.', u'エラーを発生させる必要があります',
+     u'end punctuation: "." in string, "。" not in translation'),
+    ('ja', 'Should raise an error.', u'エラーを発生させる必要があります.',
+     u'end punctuation: "." in string, "。" not in translation'),
+    ('zh-Hans', 'Should not raise an error.', u'不应引起错误。', ''),
+    ('zh-Hans', 'Should raise an error', u'应该会出现一个错误。',
+     u'end punctuation: "。" in translation, "." not in string'),
+    ('zh-Hans', 'Should raise an error.', u'应该会出现一个错误',
+     u'end punctuation: "." in string, "。" not in translation'),
+    ('zh-Hans', 'Should raise an error.', u'应该会出现一个错误.',
+     u'end punctuation: "." in string, "。" not in translation'),
+])
+def test_check_punct__full_stop__ja_zh(language, msgid, msgstr, error_message):
+    """Test punctuation with non-latin full-stops."""
+    msg = PoMessage('translation.po', 42, {}, 'utf-8', False, False, False)
+    msg.messages = [(msgid, msgstr)]
+    errors = PoMessage.check_punct(msg, language)
+    if error_message:
+        assert error_message in errors[0].message
+    else:
+        assert not errors