Commit 9746afad authored by Michal Čihař's avatar Michal Čihař

Pass language object when creating new translation

This way we will get information about plurals as well
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 388c9107
......@@ -719,7 +719,7 @@ class FileFormat(object):
return mask.replace('*', cls.get_language_code(code))
@classmethod
def add_language(cls, filename, code, base):
def add_language(cls, filename, language, base):
'''
Adds new language file.
'''
......@@ -728,10 +728,10 @@ class FileFormat(object):
if not os.path.exists(dirname):
os.makedirs(dirname)
cls.create_new_file(filename, code, base)
cls.create_new_file(filename, language, base)
@classmethod
def create_new_file(cls, filename, code, base):
def create_new_file(cls, filename, language, base):
"""Handles creation of new translation file."""
if cls.new_translation is None:
raise ValueError('Not supported')
......@@ -770,15 +770,15 @@ class FileFormat(object):
return
@staticmethod
def untranslate_store(store, code)
def untranslate_store(store, language):
"""Removes translations from ttkit store"""
store.settargetlanguage(code)
store.settargetlanguage(language.code)
for unit in store.units:
if unit.istranslatable():
unit.markfuzzy()
if unit.hasplural():
unit.settarget([''])
unit.settarget([''] * language.nplurals)
else:
unit.settarget('')
......@@ -881,11 +881,11 @@ class PoFormat(FileFormat):
return False
@classmethod
def create_new_file(cls, filename, code, base):
def create_new_file(cls, filename, language, base):
"""Handles creation of new translation file."""
store = pofile.parsefile(base)
self.untranslate_store(store, code)
cls.untranslate_store(store, language)
store.savefile(filename)
......@@ -945,10 +945,10 @@ class TSFormat(FileFormat):
return True
@classmethod
def create_new_file(cls, filename, code, base):
def create_new_file(cls, filename, language, base):
store = tsfile.parsefile(base)
self.untranslate_store(store, code)
cls.untranslate_store(store, language)
store.savefile(filename)
......@@ -991,10 +991,10 @@ class XliffFormat(FileFormat):
return False
@classmethod
def create_new_file(cls, filename, code, base):
def create_new_file(cls, filename, language, base):
"""Handles creation of new translation file."""
content = xlifffile.parsefile(base)
content.settargetlanguage(code)
content.settargetlanguage(language.code)
content.savefile(filename)
def _find_unit_mono(self, context, store):
......@@ -1155,7 +1155,7 @@ class JSONFormat(FileFormat):
return True
@classmethod
def create_new_file(cls, filename, code, base):
def create_new_file(cls, filename, language, base):
"""Handles creation of new translation file."""
content = b'{}\n'
if base:
......
......@@ -1438,7 +1438,7 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
self.file_format_cls.add_language(
fullname,
language.code,
language,
base_filename
)
......
......@@ -34,6 +34,7 @@ import six
from translate.storage.po import pofile
from weblate.lang.models import Language
from weblate.trans.formats import (
AutoFormat, PoFormat, AndroidFormat, PropertiesFormat,
JSONFormat, RESXFormat, PhpFormat, XliffFormat, TSFormat,
......@@ -170,7 +171,7 @@ class AutoFormatTest(SimpleTestCase):
suffix='.{0}'.format(self.EXT),
mode='w+'
)
self.FORMAT.add_language(out.name, 'cs', self.BASE)
self.FORMAT.add_language(out.name, Language(code='cs'), self.BASE)
data = out.read()
self.assertTrue(self.MATCH in data)
out.close()
......@@ -194,7 +195,7 @@ class PoFormatTest(AutoFormatTest):
def test_add_encoding(self):
out = tempfile.NamedTemporaryFile()
self.FORMAT.add_language(out.name, 'cs', TEST_POT_UNICODE)
self.FORMAT.add_language(out.name, Language(code='cs'), TEST_POT_UNICODE)
data = out.read().decode('utf-8')
self.assertTrue('Michal Čihař' in data)
out.close()
......
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