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
40e845b9
Commit
40e845b9
authored
Feb 15, 2016
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix dictionary downloads with ttkit 1.14.0
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
5b127214
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
15 deletions
+30
-15
weblate/trans/formats.py
weblate/trans/formats.py
+17
-10
weblate/trans/tests/test_dictionary.py
weblate/trans/tests/test_dictionary.py
+1
-1
weblate/trans/views/dictionary.py
weblate/trans/views/dictionary.py
+12
-4
No files found.
weblate/trans/formats.py
View file @
40e845b9
...
@@ -417,6 +417,16 @@ class FileFormat(object):
...
@@ -417,6 +417,16 @@ class FileFormat(object):
new_translation
=
None
new_translation
=
None
autoload
=
()
autoload
=
()
@
staticmethod
def
serialize
(
store
):
"""Serialize given ttkit store"""
if
hasattr
(
store
,
'serialize'
):
# ttkit API since 1.14.0
return
bytes
(
store
)
else
:
# ttkit API 1.13.0 and older
return
str
(
store
)
@
classmethod
@
classmethod
def
parse
(
cls
,
storefile
,
template_store
=
None
,
language_code
=
None
):
def
parse
(
cls
,
storefile
,
template_store
=
None
,
language_code
=
None
):
"""Parses store and returns FileFormat instance."""
"""Parses store and returns FileFormat instance."""
...
@@ -676,13 +686,7 @@ class FileFormat(object):
...
@@ -676,13 +686,7 @@ class FileFormat(object):
return
False
return
False
if
cls
.
monolingual
is
False
:
if
cls
.
monolingual
is
False
:
if
hasattr
(
store
,
'serialize'
):
if
cls
.
serialize
(
store
)
==
b''
:
# ttkit API since 1.14.0
storebytes
=
bytes
(
store
)
else
:
# ttkit API 1.13.0 and older
storebytes
=
str
(
store
)
if
storebytes
==
b''
:
return
False
return
False
return
True
return
True
...
@@ -832,7 +836,7 @@ class PoFormat(FileFormat):
...
@@ -832,7 +836,7 @@ class PoFormat(FileFormat):
mounit
.
msgctxt
=
[
context
]
mounit
.
msgctxt
=
[
context
]
mounit
.
target
=
unit
.
target
mounit
.
target
=
unit
.
target
outputfile
.
addunit
(
mounit
)
outputfile
.
addunit
(
mounit
)
return
s
tr
(
outputfile
)
return
s
elf
.
serialize
(
outputfile
)
def
get_language_pack_meta
(
self
):
def
get_language_pack_meta
(
self
):
'''
'''
...
@@ -1248,7 +1252,7 @@ class CSVFormat(FileFormat):
...
@@ -1248,7 +1252,7 @@ class CSVFormat(FileFormat):
if
store
.
fieldnames
!=
[
'location'
,
'source'
,
'target'
]:
if
store
.
fieldnames
!=
[
'location'
,
'source'
,
'target'
]:
return
store
return
store
if
not
isinstance
(
content
,
six
.
string_types
):
if
not
isinstance
(
content
,
six
.
string_types
)
and
six
.
PY3
:
content
=
content
.
decode
(
'utf-8'
)
content
=
content
.
decode
(
'utf-8'
)
fileobj
=
csv
.
StringIO
(
content
)
fileobj
=
csv
.
StringIO
(
content
)
...
@@ -1264,7 +1268,10 @@ class CSVFormat(FileFormat):
...
@@ -1264,7 +1268,10 @@ class CSVFormat(FileFormat):
return
store
return
store
result
=
storeclass
(
fieldnames
=
[
'source'
,
'target'
])
result
=
storeclass
(
fieldnames
=
[
'source'
,
'target'
])
result
.
parse
(
content
.
encode
(
'utf-8'
))
if
six
.
PY3
:
result
.
parse
(
content
.
encode
(
'utf-8'
))
else
:
result
.
parse
(
content
)
return
result
return
result
...
...
weblate/trans/tests/test_dictionary.py
View file @
40e845b9
...
@@ -48,7 +48,7 @@ class DictionaryTest(ViewTestCase):
...
@@ -48,7 +48,7 @@ class DictionaryTest(ViewTestCase):
})
})
def
import_file
(
self
,
filename
,
**
kwargs
):
def
import_file
(
self
,
filename
,
**
kwargs
):
with
open
(
filename
)
as
handle
:
with
open
(
filename
,
'rb'
)
as
handle
:
params
=
{
'file'
:
handle
}
params
=
{
'file'
:
handle
}
params
.
update
(
kwargs
)
params
.
update
(
kwargs
)
return
self
.
client
.
post
(
return
self
.
client
.
post
(
...
...
weblate/trans/views/dictionary.py
View file @
40e845b9
...
@@ -30,10 +30,12 @@ from django.contrib.auth.decorators import permission_required
...
@@ -30,10 +30,12 @@ from django.contrib.auth.decorators import permission_required
from
django.core.paginator
import
Paginator
,
EmptyPage
,
PageNotAnInteger
from
django.core.paginator
import
Paginator
,
EmptyPage
,
PageNotAnInteger
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
import
six
from
six.moves.urllib.parse
import
urlencode
from
six.moves.urllib.parse
import
urlencode
from
weblate.trans.models
import
Translation
,
Dictionary
,
Change
from
weblate.trans.models
import
Translation
,
Dictionary
,
Change
from
weblate.lang.models
import
Language
from
weblate.lang.models
import
Language
from
weblate.trans.formats
import
FileFormat
from
weblate.trans.site
import
get_site_url
from
weblate.trans.site
import
get_site_url
from
weblate.trans.util
import
report_error
from
weblate.trans.util
import
report_error
from
weblate.trans.forms
import
WordForm
,
DictUploadForm
,
LetterForm
from
weblate.trans.forms
import
WordForm
,
DictUploadForm
,
LetterForm
...
@@ -164,6 +166,7 @@ def upload_dictionary(request, project, lang):
...
@@ -164,6 +166,7 @@ def upload_dictionary(request, project, lang):
)
)
)
)
except
Exception
as
error
:
except
Exception
as
error
:
raise
report_error
(
error
,
sys
.
exc_info
(),
request
)
report_error
(
error
,
sys
.
exc_info
(),
request
)
messages
.
error
(
messages
.
error
(
request
,
_
(
'File upload has failed: %s'
)
%
force_text
(
error
)
request
,
_
(
'File upload has failed: %s'
)
%
force_text
(
error
)
...
@@ -231,7 +234,7 @@ def download_dictionary_ttkit(export_format, prj, lang, words):
...
@@ -231,7 +234,7 @@ def download_dictionary_ttkit(export_format, prj, lang, words):
store
.
addunit
(
unit
)
store
.
addunit
(
unit
)
# Save to response
# Save to response
response
.
write
(
str
(
store
))
response
.
write
(
FileFormat
.
serialize
(
store
))
return
response
return
response
...
@@ -271,9 +274,14 @@ def download_dictionary(request, project, lang):
...
@@ -271,9 +274,14 @@ def download_dictionary(request, project, lang):
writer
.
writerow
((
'source'
,
'target'
))
writer
.
writerow
((
'source'
,
'target'
))
for
word
in
words
.
iterator
():
for
word
in
words
.
iterator
():
writer
.
writerow
((
if
six
.
PY2
:
word
.
source
.
encode
(
'utf8'
),
word
.
target
.
encode
(
'utf8'
)
writer
.
writerow
((
))
word
.
source
.
encode
(
'utf8'
),
word
.
target
.
encode
(
'utf8'
)
))
else
:
writer
.
writerow
((
word
.
source
,
word
.
target
))
return
response
return
response
...
...
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