Commit 285273d6 authored by Michal Čihař's avatar Michal Čihař

Support for translation components without translations

Once we're able to add new translations, it's not necessary to have one
existing, users can add new one.

Fixes #878
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 9edb49e1
......@@ -16,6 +16,7 @@ Released on ? 2015.
* Added support for generating contributor stats.
* Site wide search can search only in one language.
* Improve quality checks for Armenian.
* Support for starting translation components without existing translations.
weblate 2.4
-----------
......
......@@ -1135,7 +1135,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
'''
Validates that there are no double language codes found in the files.
'''
if len(matches) == 0:
if len(matches) == 0 and not self.can_add_new_language():
raise ValidationError(_('The mask did not match any files!'))
langs = set()
translated_langs = set()
......
......@@ -180,6 +180,14 @@ class RepoTestCase(TestCase):
'po/*.po',
)
def create_po_empty(self):
return self._create_subproject(
'po',
'po-empty/*.po',
new_base='po-empty/hello.pot',
new_lang='add',
)
def create_po_mercurial(self):
return self._create_subproject(
'po',
......@@ -352,7 +360,7 @@ class SubProjectTest(RepoTestCase):
"""
SubProject object testing.
"""
def verify_subproject(self, project, translations, lang, units,
def verify_subproject(self, project, translations, lang=None, units=0,
unit='Hello, world!\n', fail=False):
# Validation
if fail:
......@@ -368,12 +376,13 @@ class SubProjectTest(RepoTestCase):
self.assertEqual(
project.translation_set.count(), translations
)
# Grab translation
translation = project.translation_set.get(language_code=lang)
# Count units in it
self.assertEqual(translation.unit_set.count(), units)
# Check whether unit exists
self.assertTrue(translation.unit_set.filter(source=unit).exists())
if lang is not None:
# Grab translation
translation = project.translation_set.get(language_code=lang)
# Count units in it
self.assertEqual(translation.unit_set.count(), units)
# Check whether unit exists
self.assertTrue(translation.unit_set.filter(source=unit).exists())
def test_create(self):
project = self.create_subproject()
......@@ -478,6 +487,10 @@ class SubProjectTest(RepoTestCase):
project = self.create_po_mercurial()
self.verify_subproject(project, 3, 'cs', 4)
def test_create_po_empty(self):
project = self.create_po_empty()
self.verify_subproject(project, 0)
def test_create_po_link(self):
project = self.create_po_link()
self.verify_subproject(project, 4, 'cs', 4)
......
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