Commit 49767a18 authored by Michal Čihař's avatar Michal Čihař

Factor out filename calculation to file format class (issue #480)

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 0231a705
......@@ -555,6 +555,17 @@ class FileFormat(object):
'''
return True
@staticmethod
def get_language_filename(path, mask, code):
"""
Return full filename of a language file for given
path, filemaks and language code.
"""
return os.path.join(
path,
mask.replace('*', code)
)
@staticmethod
def add_language(filename, code, base):
'''
......
......@@ -1192,9 +1192,10 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
if not self.file_format_cls.is_valid_base_for_new(base_filename):
raise ValueError('Not supported operation!')
filename = os.path.join(
filename = self.file_format_cls.get_language_filename(
self.get_path(),
self.filemask.replace('*', language.code)
self.filemask,
language.code
)
# Create directory for a translation
......
......@@ -40,6 +40,8 @@ class AutoFormatTest(TestCase):
EXT = 'po'
COUNT = 5
MATCH = 'msgid_plural'
MASK = 'po/*.po'
EXPECTED_PATH = '/path/po/cs_CZ.po'
def test_parse(self):
storage = self.FORMAT(self.FILE)
......@@ -65,6 +67,14 @@ class AutoFormatTest(TestCase):
self.assertTrue(self.MATCH in data)
out.close()
def test_get_language_filename(self):
self.assertEquals(
self.FORMAT.get_language_filename(
'/path', self.MASK, 'cs_CZ'
),
self.EXPECTED_PATH
)
class PoFormatTest(AutoFormatTest):
FORMAT = PoFormat
......@@ -77,3 +87,5 @@ class AndroidFormatTest(AutoFormatTest):
EXT = 'xml'
COUNT = 0
MATCH = '<resources></resources>'
MASK = 'res/values-*/strings.xml'
EXPECTED_PATH = '/path/res/values-cs_CZ/strings.xml'
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