Commit 5889ed4e authored by Michal Čihař's avatar Michal Čihař

Add validation for empty language code

Issue #153
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 7ddc4069
......@@ -1039,6 +1039,10 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
translated_langs = set()
for match in matches:
code = self.get_lang_code(match)
if not code:
raise ValidationError(_(
'Got empty language code for %s, please check filemask!'
) % match)
lang = Language.objects.auto_get_or_create(code=code)
if code in langs:
raise ValidationError(_(
......
......@@ -689,6 +689,32 @@ class SubProjectTest(RepoTestCase):
subproject.run_hook('true')
)
def test_lang_code(self):
subproject = SubProject()
subproject.filemask = 'Solution/Project/Resources*.resx'
self.assertEqual(
subproject.get_lang_code('Solution/Project/Resources.es-mx.resx'),
'.es-mx'
)
self.assertEqual(
subproject.get_lang_code('Solution/Project/Resources.resx'),
''
)
self.assertRaisesMessage(
ValidationError,
'Got empty language code for '
'Solution/Project/Resources.resx, please check filemask!',
subproject.clean_lang_codes,
[
'Solution/Project/Resources.resx',
'Solution/Project/Resources.de.resx',
'Solution/Project/Resources.es.resx',
'Solution/Project/Resources.es-mx.resx',
'Solution/Project/Resources.fr.resx',
'Solution/Project/Resources.fr-fr.resx',
]
)
class TranslationTest(RepoTestCase):
"""
......
Markdown is supported
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