Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Weblate
gajim
Commits
87504e39
Commit
87504e39
authored
13 years ago
by
Yann Leboulanger
Browse files
Options
Downloads
Patches
Plain Diff
make google translation plugin work with unicode char
parent
9ed4b62d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/google_translation/manifest.ini
+1
-1
1 addition, 1 deletion
plugins/google_translation/manifest.ini
plugins/google_translation/plugin.py
+7
-16
7 additions, 16 deletions
plugins/google_translation/plugin.py
with
8 additions
and
17 deletions
plugins/google_translation/manifest.ini
+
1
−
1
View file @
87504e39
[info]
name:
Google
Translation
short_name:
google_translation
version:
0.
1
version:
0.
2
description:
Translates
(currently
only
incoming)
messages
using
Google
Translate.
authors
=
Mateusz Biliński <mateusz@bilinski.it>
homepage
=
http://blog.bilinski.it
...
...
This diff is collapsed.
Click to expand it.
plugins/google_translation/plugin.py
+
7
−
16
View file @
87504e39
...
...
@@ -26,12 +26,10 @@ Translates (currently only incoming) messages using Google Translate.
:license: GPL
'''
import
re
import
json
import
urllib2
import
HTMLParser
import
new
import
gtk
from
pprint
import
pformat
from
sys
import
getfilesystemencoding
import
chat_control
...
...
@@ -43,7 +41,6 @@ from common import gajim
from
plugins
import
GajimPlugin
from
plugins.helpers
import
log_calls
,
log
from
common
import
ged
from
common
import
nec
languages
=
{
_
(
'
Afrikaans
'
):
'
af
'
,
...
...
@@ -127,9 +124,6 @@ class GoogleTranslationPlugin(GajimPlugin):
}
self
.
controls
=
[]
self
.
translated_text_re
=
re
.
compile
(
r
'
google.language.callbacks.id100\(\'22\',
'
'
{(?P<text>[^\}]*)}, 200, null, 200\)
'
)
@log_calls
(
'
GoogleTranslationPlugin
'
)
def
translate_text
(
self
,
account
,
text
,
from_lang
,
to_lang
):
...
...
@@ -137,8 +131,8 @@ class GoogleTranslationPlugin(GajimPlugin):
# Translate.
quoted_text
=
urllib2
.
quote
(
text
.
encode
(
getfilesystemencoding
()))
# prepare url
translation_url
=
u
'
http://
www
.google.com/
uds/Gtranslate?callback=
'
\
'
google.
language
.callbacks.id100&context=22&
q=%(quoted_text)s&
'
\
translation_url
=
u
'
http
s
://
ajax
.google
apis
.com/
ajax/services/
'
\
'
language
/translate?
q=%(quoted_text)s&
'
\
'
langpair=%(from_lang)s%%7C%(to_lang)s&key=notsupplied&v=1.0
'
%
\
locals
()
...
...
@@ -146,17 +140,14 @@ class GoogleTranslationPlugin(GajimPlugin):
if
not
results
:
return
text
result
=
self
.
translated_text_re
.
search
(
results
)
if
not
result
:
return
text
dict_
=
eval
(
'
{
'
+
result
.
group
(
'
text
'
)
+
'
}
'
)
result
=
json
.
loads
(
results
)
translated_text
=
dict_
.
get
(
'
translatedText
'
,
''
)
if
result
.
get
(
'
responseStatus
'
,
''
)
!=
200
:
return
text
translated_text
=
result
[
'
responseData
'
].
get
(
'
translatedText
'
,
''
)
if
translated_text
:
try
:
translated_text
=
unicode
(
translated_text
,
'
unicode_escape
'
)
htmlparser
=
HTMLParser
.
HTMLParser
()
translated_text
=
htmlparser
.
unescape
(
translated_text
)
except
Exception
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment