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
64470a17
Commit
64470a17
authored
Feb 13, 2016
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make machine translations compatible with Python 3
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
84e9ffcb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
7 deletions
+11
-7
weblate/trans/machine/base.py
weblate/trans/machine/base.py
+7
-3
weblate/trans/machine/tmserver.py
weblate/trans/machine/tmserver.py
+1
-1
weblate/trans/tests/test_machine.py
weblate/trans/tests/test_machine.py
+3
-3
No files found.
weblate/trans/machine/base.py
View file @
64470a17
...
...
@@ -21,6 +21,8 @@
Base code for machine translation services.
'''
from
__future__
import
unicode_literals
import
sys
import
json
...
...
@@ -75,9 +77,9 @@ class MachineTranslation(object):
'''
# Encode params
if
len
(
kwargs
)
>
0
:
params
=
urlencode
(
kwargs
)
params
=
urlencode
(
kwargs
)
.
encode
(
'utf-8'
)
else
:
params
=
''
params
=
b
''
# Store for exception handling
self
.
request_url
=
url
...
...
@@ -104,8 +106,10 @@ class MachineTranslation(object):
# Read and possibly convert response
text
=
handle
.
read
()
# Needed for Microsoft
if
text
.
startswith
(
'
\
xef
\
xbb
\
xbf
'
)
:
if
text
[:
3
]
==
b'
\
xef
\
xbb
\
xbf
'
:
text
=
text
.
decode
(
'UTF-8-sig'
)
else
:
text
=
text
.
decode
(
'utf-8'
)
# Replace literal \t
text
=
text
.
strip
().
replace
(
'
\
t
'
,
'
\
\
t'
...
...
weblate/trans/machine/tmserver.py
View file @
64470a17
...
...
@@ -70,7 +70,7 @@ class TMServerTranslation(MachineTranslation):
self
.
url
,
quote
(
appsettings
.
SOURCE_LANGUAGE
),
quote
(
language
),
quote
(
text
[:
500
].
encode
(
'utf-8'
).
replace
(
'
\
r
'
,
'
'
)),
quote
(
text
[:
500
].
replace
(
'
\
r
'
,
' '
).
encode
(
'utf-8
'
)),
)
response
=
self
.
json_req
(
url
)
...
...
weblate/trans/tests/test_machine.py
View file @
64470a17
...
...
@@ -195,18 +195,18 @@ class MachineTranslationTest(TestCase):
httpretty
.
register_uri
(
httpretty
.
GET
,
'https://www.googleapis.com/language/translate/v2/languages'
,
body
=
'{"data": {"languages": [ { "language": "cs" }]}}'
body
=
b
'{"data": {"languages": [ { "language": "cs" }]}}'
)
httpretty
.
register_uri
(
httpretty
.
GET
,
'https://www.googleapis.com/language/translate/v2/'
,
body
=
'{"data":{"translations":[{"translatedText":"svet"}]}}'
body
=
b
'{"data":{"translations":[{"translatedText":"svet"}]}}'
)
machine
=
GoogleTranslation
()
self
.
assertTranslate
(
machine
)
@
httpretty
.
activate
def
test_google_invalid
(
self
):
def
test_google_invalid
x
(
self
):
"""Test handling of server failure."""
cache
.
delete
(
'%s-languages'
%
GoogleTranslation
().
mtid
)
httpretty
.
register_uri
(
...
...
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