Commit d43d0435 authored by Weblate's avatar Weblate

Merge remote-tracking branch 'origin/master'

parents 171f9b56 9024b6aa
...@@ -149,8 +149,8 @@ class FileUnit(object): ...@@ -149,8 +149,8 @@ class FileUnit(object):
# Need to apply special magic for plurals here # Need to apply special magic for plurals here
# as there is no singlular/plural in the source string # as there is no singlular/plural in the source string
return join_plural([ return join_plural([
self.unit.source.replace('(s)', ''), self.unit.source,
self.unit.source.replace('(s)', 's'), self.unit.source,
]) ])
if self.is_unit_key_value(): if self.is_unit_key_value():
# Need to decode property encoded string # Need to decode property encoded string
......
...@@ -147,10 +147,10 @@ class RepoTestCase(TestCase): ...@@ -147,10 +147,10 @@ class RepoTestCase(TestCase):
'po-mono/en.po', 'po-mono/en.po',
) )
def create_ts(self): def create_ts(self, suffix=''):
return self._create_subproject( return self._create_subproject(
'ts', 'ts',
'ts/*.ts', 'ts{0}/*.ts'.format(suffix),
) )
def create_iphone(self): def create_iphone(self):
...@@ -355,8 +355,8 @@ class SubProjectTest(RepoTestCase): ...@@ -355,8 +355,8 @@ class SubProjectTest(RepoTestCase):
self.verify_subproject(project, 1, 'cs', 4) self.verify_subproject(project, 1, 'cs', 4)
def test_create_ts(self): def test_create_ts(self):
project = self.create_ts() project = self.create_ts('-translated')
self.verify_subproject(project, 1, 'cs', 4, 'Hello, world!') self.verify_subproject(project, 1, 'cs', 4)
unit = Unit.objects.get(source__startswith='Orangutan') unit = Unit.objects.get(source__startswith='Orangutan')
self.assertTrue(unit.is_plural()) self.assertTrue(unit.is_plural())
...@@ -367,7 +367,7 @@ class SubProjectTest(RepoTestCase): ...@@ -367,7 +367,7 @@ class SubProjectTest(RepoTestCase):
self.assertFalse(unit.is_plural()) self.assertFalse(unit.is_plural())
self.assertTrue(unit.translated) self.assertTrue(unit.translated)
self.assertFalse(unit.fuzzy) self.assertFalse(unit.fuzzy)
self.assertEqual(unit.target, 'Hello, world!') self.assertEqual(unit.target, 'Hello, world!\n')
unit = Unit.objects.get(source__startswith='Thank ') unit = Unit.objects.get(source__startswith='Thank ')
self.assertFalse(unit.is_plural()) self.assertFalse(unit.is_plural())
......
...@@ -34,6 +34,7 @@ from accounts.models import Profile ...@@ -34,6 +34,7 @@ from accounts.models import Profile
from PIL import Image from PIL import Image
import re import re
import time import time
import unittest
from urlparse import urlsplit from urlparse import urlsplit
from cStringIO import StringIO from cStringIO import StringIO
...@@ -97,7 +98,7 @@ class ViewTestCase(RepoTestCase): ...@@ -97,7 +98,7 @@ class ViewTestCase(RepoTestCase):
def get_unit(self, source='Hello, world!\n'): def get_unit(self, source='Hello, world!\n'):
translation = self.get_translation() translation = self.get_translation()
return translation.unit_set.get(source=source) return translation.unit_set.get(source__startswith=source)
def change_unit(self, target): def change_unit(self, target):
unit = self.get_unit() unit = self.get_unit()
...@@ -105,7 +106,10 @@ class ViewTestCase(RepoTestCase): ...@@ -105,7 +106,10 @@ class ViewTestCase(RepoTestCase):
unit.save_backend(self.get_request('/')) unit.save_backend(self.get_request('/'))
def edit_unit(self, source, target, **kwargs): def edit_unit(self, source, target, **kwargs):
unit = self.get_translation().unit_set.get(source=source) '''
Does edit single unit using web interface.
'''
unit = self.get_unit(source)
params = { params = {
'checksum': unit.checksum, 'checksum': unit.checksum,
'target': target, 'target': target,
...@@ -341,6 +345,8 @@ class EditTest(ViewTestCase): ...@@ -341,6 +345,8 @@ class EditTest(ViewTestCase):
''' '''
Tests for manipulating translation. Tests for manipulating translation.
''' '''
has_plurals = True
def setUp(self): def setUp(self):
super(EditTest, self).setUp() super(EditTest, self).setUp()
self.translation = self.subproject.translation_set.get( self.translation = self.subproject.translation_set.get(
...@@ -390,6 +396,38 @@ class EditTest(ViewTestCase): ...@@ -390,6 +396,38 @@ class EditTest(ViewTestCase):
self.assertFalse(unit.fuzzy) self.assertFalse(unit.fuzzy)
self.assertBackend(1) self.assertBackend(1)
def test_plurals(self):
'''
Test plural editing.
'''
if not self.has_plurals:
return
response = self.edit_unit(
'Orangutan',
u'Opice má %d banán.\n',
target_1=u'Opice má %d banány.\n',
target_2=u'Opice má %d banánů.\n',
)
# We should get to second message
self.assertRedirectsOffset(response, self.translate_url, 1)
# Check translations
unit = self.get_unit('Orangutan')
plurals = unit.get_target_plurals()
self.assertEquals(len(plurals), 3)
self.assertEquals(
plurals[0],
u'Opice má %d banán.\n',
)
self.assertEquals(
plurals[1],
u'Opice má %d banány.\n',
)
self.assertEquals(
plurals[2],
u'Opice má %d banánů.\n',
)
def test_merge(self): def test_merge(self):
# Translate unit to have something to start with # Translate unit to have something to start with
response = self.edit_unit( response = self.edit_unit(
...@@ -613,6 +651,8 @@ class EditTest(ViewTestCase): ...@@ -613,6 +651,8 @@ class EditTest(ViewTestCase):
class EditResourceTest(EditTest): class EditResourceTest(EditTest):
has_plurals = False
def create_subproject(self): def create_subproject(self):
return self.create_android() return self.create_android()
...@@ -623,16 +663,22 @@ class EditPoMonoTest(EditTest): ...@@ -623,16 +663,22 @@ class EditPoMonoTest(EditTest):
class EditIphoneTest(EditTest): class EditIphoneTest(EditTest):
has_plurals = False
def create_subproject(self): def create_subproject(self):
return self.create_iphone() return self.create_iphone()
class EditJavaTest(EditTest): class EditJavaTest(EditTest):
has_plurals = False
def create_subproject(self): def create_subproject(self):
return self.create_java() return self.create_java()
class EditXliffTest(EditTest): class EditXliffTest(EditTest):
has_plurals = False
def create_subproject(self): def create_subproject(self):
return self.create_xliff() return self.create_xliff()
...@@ -642,6 +688,11 @@ class EditLinkTest(EditTest): ...@@ -642,6 +688,11 @@ class EditLinkTest(EditTest):
return self.create_link() return self.create_link()
class EditTSTest(EditTest):
def create_subproject(self):
return self.create_ts()
class SuggestionsTest(ViewTestCase): class SuggestionsTest(ViewTestCase):
def add_suggestion_1(self): def add_suggestion_1(self):
return self.edit_unit( return self.edit_unit(
......
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