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

Correctly handle plurals for Qt TS files

Fixes #418
parent 301d15f0
...@@ -26,9 +26,10 @@ from translate.storage.properties import propunit, propfile ...@@ -26,9 +26,10 @@ from translate.storage.properties import propunit, propfile
from translate.storage.xliff import xliffunit from translate.storage.xliff import xliffunit
from translate.storage.po import pounit, pofile from translate.storage.po import pounit, pofile
from translate.storage.php import phpunit from translate.storage.php import phpunit
from translate.storage.ts2 import tsunit
from translate.storage import mo from translate.storage import mo
from translate.storage import factory from translate.storage import factory
from trans.util import get_string from trans.util import get_string, join_plural
from translate.misc import quote from translate.misc import quote
import weblate import weblate
import subprocess import subprocess
...@@ -142,6 +143,15 @@ class FileUnit(object): ...@@ -142,6 +143,15 @@ class FileUnit(object):
''' '''
Returns source string from a ttkit unit. Returns source string from a ttkit unit.
''' '''
if (isinstance(self.mainunit, tsunit)
and self.template is None
and self.mainunit.hasplural()):
# Need to apply special magic for plurals here
# as there is no singlular/plural in the source string
return join_plural([
self.unit.source.replace('(s)', ''),
self.unit.source.replace('(s)', 's'),
])
if self.is_unit_key_value(): if self.is_unit_key_value():
# Need to decode property encoded string # Need to decode property encoded string
if isinstance(self.mainunit, propunit): if isinstance(self.mainunit, propunit):
......
...@@ -30,7 +30,7 @@ from django.core.exceptions import ValidationError ...@@ -30,7 +30,7 @@ from django.core.exceptions import ValidationError
import shutil import shutil
import os import os
import git import git
from trans.models import Project, SubProject from trans.models import Project, SubProject, Unit
from weblate import appsettings from weblate import appsettings
from trans.tests.test_util import get_test_file from trans.tests.test_util import get_test_file
...@@ -147,6 +147,12 @@ class RepoTestCase(TestCase): ...@@ -147,6 +147,12 @@ class RepoTestCase(TestCase):
'po-mono/en.po', 'po-mono/en.po',
) )
def create_ts(self):
return self._create_subproject(
'ts',
'ts/*.ts',
)
def create_iphone(self): def create_iphone(self):
return self._create_subproject( return self._create_subproject(
'strings', 'strings',
...@@ -348,6 +354,12 @@ class SubProjectTest(RepoTestCase): ...@@ -348,6 +354,12 @@ class SubProjectTest(RepoTestCase):
project = self.create_iphone() project = self.create_iphone()
self.verify_subproject(project, 1, 'cs', 4) self.verify_subproject(project, 1, 'cs', 4)
def test_create_ts(self):
project = self.create_ts()
self.verify_subproject(project, 1, 'cs', 4, 'Hello, world!')
unit = Unit.objects.get(source__startswith='Orangutan')
self.assertTrue(unit.is_plural)
def test_create_po_pot(self): def test_create_po_pot(self):
project = self._create_subproject( project = self._create_subproject(
'po', 'po',
......
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