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