Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
ba22db82
Commit
ba22db82
authored
Jan 28, 2016
by
matejcik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reject uploaded file with mismatched plural form
parent
1c133831
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
3 deletions
+75
-3
weblate/trans/models/translation.py
weblate/trans/models/translation.py
+7
-0
weblate/trans/tests/data/cs-badplurals.po
weblate/trans/tests/data/cs-badplurals.po
+42
-0
weblate/trans/tests/test_files.py
weblate/trans/tests/test_files.py
+26
-3
No files found.
weblate/trans/models/translation.py
View file @
ba22db82
...
...
@@ -1200,6 +1200,13 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
if
author
is
None
:
author
=
get_author_name
(
request
.
user
)
# Check valid plural forms
if
hasattr
(
store
.
store
,
'parseheader'
):
header
=
store
.
store
.
parseheader
()
if
'Plural-Forms'
in
header
and
\
self
.
language
.
get_plural_form
()
!=
header
[
'Plural-Forms'
]:
raise
Exception
(
'Plural forms do not match the language.'
)
# List translations we should process
# Filter out those who don't want automatic update, but keep ourselves
translations
=
Translation
.
objects
.
filter
(
...
...
weblate/trans/tests/data/cs-badplurals.po
0 → 100644
View file @
ba22db82
# Czech translations for PACKAGE package.
# Copyright (C) 2012 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# Automatically generated, 2012.
# Testing Weblate, 2015.
#
msgid ""
msgstr ""
"Project-Id-Version: Weblate Hello World 2012\n"
"Report-Msgid-Bugs-To: <noreply@example.net>\n"
"POT-Creation-Date: 2012-03-14 15:54+0100\n"
"PO-Revision-Date: 2012-03-05 15:55+0100\n"
"Last-Translator: Automatically generated\n"
"Language-Team: Test Team <noreply@weblate.org>\n"
"Language: cs\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=4; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : (n % 10 == 1) ? 3 : 2;\n"
#: main.c:11
#, c-format
msgid "Hello, world!\n"
msgstr "Ahoj světe!\n"
#: main.c:12
#, c-format
msgid "Orangutan has %d banana.\n"
msgid_plural "Orangutan has %d bananas.\n"
msgstr[0] ""
msgstr[1] ""
msgstr[2] ""
msgstr[3] ""
#: main.c:13
#, c-format
msgid "Try Weblate at <http://demo.weblate.org/>!\n"
msgstr ""
#: main.c:14
msgid "Thank you for using Weblate."
msgstr ""
weblate/trans/tests/test_files.py
View file @
ba22db82
...
...
@@ -33,6 +33,7 @@ TEST_PO = get_test_file('cs.po')
TEST_CSV
=
get_test_file
(
'cs.csv'
)
TEST_PO_BOM
=
get_test_file
(
'cs-bom.po'
)
TEST_FUZZY_PO
=
get_test_file
(
'cs-fuzzy.po'
)
TEST_BADPLURALS
=
get_test_file
(
'cs-badplurals.po'
)
TEST_MO
=
get_test_file
(
'cs.mo'
)
TEST_ANDROID
=
get_test_file
(
'strings-cs.xml'
)
...
...
@@ -52,11 +53,14 @@ class ImportBaseTest(ViewTestCase):
self
.
user
.
is_superuser
=
True
self
.
user
.
save
()
def
do_import
(
self
,
**
kwargs
):
def
do_import
(
self
,
test_file
=
None
,
follow
=
False
,
**
kwargs
):
'''
Helper to perform file import.
'''
with
open
(
self
.
test_file
)
as
handle
:
if
test_file
is
None
:
test_file
=
self
.
test_file
with
open
(
test_file
)
as
handle
:
params
=
{
'file'
:
handle
}
params
.
update
(
kwargs
)
return
self
.
client
.
post
(
...
...
@@ -64,7 +68,8 @@ class ImportBaseTest(ViewTestCase):
'upload_translation'
,
kwargs
=
self
.
kw_translation
),
params
params
,
follow
=
follow
)
...
...
@@ -209,6 +214,24 @@ class ImportTest(ImportBaseTest):
)
class
ImportErrorTest
(
ImportBaseTest
):
'''
Testing import of broken files.
'''
def
test_mismatched_plurals
(
self
):
'''
Test importing a file with different number of plural forms.
In response to issue #900
'''
from
django.contrib.messages
import
ERROR
response
=
self
.
do_import
(
test_file
=
TEST_BADPLURALS
,
follow
=
True
)
self
.
assertRedirects
(
response
,
self
.
translation_url
)
messages
=
list
(
response
.
context
[
"messages"
])
self
.
assertEquals
(
len
(
messages
),
1
)
self
.
assertEquals
(
messages
[
0
].
level
,
ERROR
)
self
.
assertIn
(
"Plural forms do not match"
,
messages
[
0
].
message
)
class
BOMImportTest
(
ImportTest
):
test_file
=
TEST_PO_BOM
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment