Commit 3bb31234 authored by intrigeri's avatar intrigeri
Browse files

lint_po: support locales with "@" in their name, such as ru@petr1708 (Closes: #17554)

parent 9e4b84cb
......@@ -108,7 +108,7 @@ class PoFile:
"""@returns: language of filename, possibly ending with an underscore
followed by the territory or script"""
name = os.path.basename(self.fname)
m = re.match(r"^(?:[^.].*\.)?(?P<lang>[A-Za-z_]+)\.po$", name)
m = re.match(r"^(?:[^.].*\.)?(?P<lang>[A-Za-z0-9_@]+)\.po$", name)
if not m:
raise NoLanguageError(self.fname)
return m.group("lang")
......@@ -119,7 +119,7 @@ class PoFile:
# a script suffix (e.g. "_Latn") starts with an underscore,
# followed by the script name in title case, which we
# approximate as an upper case letter followed by a lower case one
m = re.match(r"(?P<lang_without_script>.*)_[A-Z][a-z][A-Za-z]*$", lang)
m = re.match(r"^(?P<lang_without_script>.*?)(_[A-Z][a-z][A-Za-z]*)?(@[A-Za-z0-9]+)?$", lang)
if m:
return m.group("lang_without_script")
else:
......
......@@ -97,6 +97,7 @@ class TestCheckPo(unittest.TestCase):
self.assertEqual(lint_po.PoFile("index.de.po").lang(), "de")
self.assertEqual(lint_po.PoFile("x/a/a.fb.xx.po").lang(), "xx")
self.assertEqual(lint_po.PoFile("a.po").lang(), "a")
self.assertEqual(lint_po.PoFile("ru@petr1708.po").lang(), "ru@petr1708")
_p = lint_po.PoFile(".de.po")
with self.assertRaises(lint_po.NoLanguageError, msg=_p.fname) as e:
......@@ -117,6 +118,8 @@ class TestCheckPo(unittest.TestCase):
self.assertEqual(lint_po.PoFile("index.de_DE.po").lang_without_script(), "de_DE")
self.assertEqual(lint_po.PoFile("index.sr_Latn.po").lang_without_script(), "sr")
self.assertEqual(lint_po.PoFile("index.sr_LAtn.po").lang_without_script(), "sr_LAtn")
self.assertEqual(lint_po.PoFile("ru@petr1708.po").lang_without_script(), "ru")
self.assertEqual(lint_po.PoFile("ru_RU@petr1708.po").lang_without_script(), "ru_RU")
def test_needs_rewrap(self):
with lint_po.pofile_readonly(os.path.join(DIRNAME, "checkPo/length")) as poFile:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment