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