Commit 47740994 authored by Michal Čihař's avatar Michal Čihař

Support for adding new translations in XLIFF.

Fixes #801
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 97d9fbc0
......@@ -21,6 +21,7 @@ Released on ? 2015.
* Projects now can have multiple owners.
* Project owners can manage themselves.
* Added support for javascript-format used in Gettext PO.
* Support for adding new translations in XLIFF.
weblate 2.3
-----------
......
......@@ -120,11 +120,6 @@ is one of many standards in this area.
XLIFF is usually used as bilingual.
.. note::
Weblate does not support adding new language to the translations using this
format. This has to be done manually in the VCS.
.. seealso::
`XLIFF on Wikipedia <https://en.wikipedia.org/wiki/XLIFF>`_,
......
......@@ -23,7 +23,7 @@ File format specific behavior.
from django.utils.translation import ugettext_lazy as _
from translate.storage.lisa import LISAfile
from translate.storage.properties import propunit, propfile
from translate.storage.xliff import xliffunit
from translate.storage.xliff import xliffunit, xlifffile
from translate.storage.po import pounit, pofile
from translate.storage.php import phpunit
from translate.storage.ts2 import tsunit
......@@ -854,6 +854,31 @@ class XliffFormat(FileFormat):
format_id = 'xliff'
loader = ('xliff', 'xlifffile')
@classmethod
def supports_new_language(cls):
'''
Checks whether we can create new language file.
'''
return True
@staticmethod
def is_valid_base_for_new(base):
'''
Checks whether base is valid.
'''
try:
xlifffile.parsefile(base)
return True
except Exception:
return False
@classmethod
def create_new_file(cls, filename, code, base):
"""Handles creation of new translation file."""
content = xlifffile.parsefile(base)
content.settargetlanguage(code)
content.savefile(filename)
@register_fileformat
class StringsFormat(FileFormat):
......
<xliff>
<file>
<body>
<trans-unit><source xml:space="preserve">Hello, world!
</source></trans-unit>
<trans-unit><source xml:space="preserve">Orangutan has %d banana.
</source></trans-unit>
<trans-unit><source xml:space="preserve">Try Weblate at &lt;http://demo.weblate.org/&gt;!
</source></trans-unit>
<trans-unit><source>Thank you for using Weblate.</source></trans-unit>
</body>
</file>
</xliff>
......@@ -24,7 +24,7 @@ import tempfile
from unittest import TestCase
from weblate.trans.formats import (
AutoFormat, PoFormat, AndroidFormat, PropertiesFormat,
JSONFormat, RESXFormat, PhpFormat,
JSONFormat, RESXFormat, PhpFormat, XliffFormat,
FILE_FORMATS,
)
from weblate.trans.tests.utils import get_test_file
......@@ -34,6 +34,7 @@ TEST_JSON = get_test_file('cs.json')
TEST_PHP = get_test_file('cs.php')
TEST_PROPERTIES = get_test_file('swing.properties')
TEST_ANDROID = get_test_file('strings.xml')
TEST_XLIFF = get_test_file('cs.xliff')
TEST_POT = get_test_file('hello.pot')
TEST_POT_UNICODE = get_test_file('unicode.pot')
TEST_RESX = get_test_file('cs.resx')
......@@ -145,6 +146,19 @@ class AndroidFormatTest(AutoFormatTest):
EXPECTED_PATH = 'res/values-cs-rCZ/strings.xml'
class XliffFormatTest(AutoFormatTest):
FORMAT = XliffFormat
FILE = TEST_XLIFF
BASE = TEST_XLIFF
MIME = 'application/x-xliff'
EXT = 'xlf'
COUNT = 4
MATCH = '<file target-language="cs">'
FIND_MATCH = u''
MASK = 'loc/*/default.xliff'
EXPECTED_PATH = 'loc/cs_CZ/default.xliff'
if 'resx' in FILE_FORMATS:
class RESXFormatTest(AutoFormatTest):
FORMAT = RESXFormat
......
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