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
ffb0b89c
Commit
ffb0b89c
authored
Mar 20, 2013
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add URL for translations
parent
b813f0af
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
4 deletions
+47
-4
trans/machine/__init__.py
trans/machine/__init__.py
+2
-2
trans/tests/js_views.py
trans/tests/js_views.py
+14
-0
trans/views/js.py
trans/views/js.py
+26
-2
weblate/urls.py
weblate/urls.py
+5
-0
No files found.
trans/machine/__init__.py
View file @
ffb0b89c
...
...
@@ -22,7 +22,7 @@ from weblate import appsettings
from
trans.util
import
load_class
# Initialize checks list
SERVICES
=
{}
MACHINE_TRANSLATION_
SERVICES
=
{}
for
path
in
appsettings
.
MACHINE_TRANSLATION_SERVICES
:
obj
=
load_class
(
path
)()
SERVICES
[
obj
.
mtid
]
=
obj
MACHINE_TRANSLATION_
SERVICES
[
obj
.
mtid
]
=
obj
trans/tests/js_views.py
View file @
ffb0b89c
...
...
@@ -24,6 +24,7 @@ Tests for AJAX/JS views.
from
trans.tests.views
import
ViewTestCase
from
django.core.urlresolvers
import
reverse
from
django.utils
import
simplejson
class
JSViewsTest
(
ViewTestCase
):
...
...
@@ -46,6 +47,19 @@ class JSViewsTest(ViewTestCase):
)
self
.
assertContains
(
response
,
'No similar strings found'
)
def
test_translate
(
self
):
unit
=
self
.
get_unit
()
response
=
self
.
client
.
get
(
reverse
(
'js-translate'
,
kwargs
=
{
'unit_id'
:
unit
.
id
}),
{
'service'
:
'dummy'
}
)
self
.
assertContains
(
response
,
'Ahoj'
)
data
=
simplejson
.
loads
(
response
.
content
)
self
.
assertEqual
(
data
,
[
'Nazdar světe!'
,
'Ahoj světe!'
]
)
def
test_get_other
(
self
):
unit
=
self
.
get_unit
()
response
=
self
.
client
.
get
(
...
...
trans/views/js.py
View file @
ffb0b89c
...
...
@@ -22,11 +22,12 @@ from django.shortcuts import render_to_response, get_object_or_404
from
django.views.decorators.cache
import
cache_page
from
weblate
import
appsettings
from
django.template
import
RequestContext
from
django.http
import
HttpResponse
from
django.contrib.auth.decorators
import
permission_required
from
django.http
import
HttpResponse
,
HttpResponseBadRequest
from
django.contrib.auth.decorators
import
permission_required
,
login_required
from
django.db.models
import
Q
from
trans.models
import
Unit
,
Check
,
Dictionary
from
trans.machine
import
MACHINE_TRANSLATION_SERVICES
from
trans.views.helper
import
SearchOptions
from
trans.decorators
import
any_permission_required
from
trans.views.helper
import
get_project
,
get_subproject
,
get_translation
...
...
@@ -74,6 +75,29 @@ def get_similar(request, unit_id):
'similar'
:
similar
,
}))
@
login_required
def
translate
(
request
,
unit_id
):
'''
AJAX handler for translating.
'''
unit
=
get_object_or_404
(
Unit
,
pk
=
int
(
unit_id
))
unit
.
check_acl
(
request
)
service_name
=
request
.
GET
.
get
(
'service'
,
'INVALID'
)
if
not
service_name
in
MACHINE_TRANSLATION_SERVICES
:
return
HttpResponseBadRequest
(
'Invalid service specified'
)
response
=
MACHINE_TRANSLATION_SERVICES
[
service_name
].
translate
(
unit
.
translation
.
language
.
code
,
unit
.
get_source_plurals
()[
0
]
)
return
HttpResponse
(
json
.
dumps
(
response
),
mimetype
=
'application/json'
)
def
get_other
(
request
,
unit_id
):
'''
...
...
weblate/urls.py
View file @
ffb0b89c
...
...
@@ -528,6 +528,11 @@ urlpatterns = patterns(
'trans.views.js.get_similar'
,
name
=
'js-similar'
,
),
url
(
r'^js/translate/(?P<unit_id>[0-9]+)/$'
,
'trans.views.js.translate'
,
name
=
'js-translate'
,
),
url
(
r'^js/other/(?P<unit_id>[0-9]+)/$'
,
'trans.views.js.get_other'
,
...
...
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