Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get the object to be translated correctly in Google Translate view (branch 7.x) #463

Open
wants to merge 3 commits into
base: 7.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/303.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Get the object to be translated correctly
[erral]
14 changes: 10 additions & 4 deletions src/plone/app/multilingual/browser/javascript/babel_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,17 @@
original_field.prepend("<div class='translator-widget' id='item_translation_" + order + "'></div>");
original_field.children('.translator-widget').click(function () {
var field = $(value).attr("rel");
// Fetch source of text to translate.
// Fetch source of text to translate.

// we use the current URL to get the context's UID
var url_parts = document.location.pathname.split('++addtranslation++')

var jsondata = {
'field': field,
'lang_source': langSource
};
'field': field,
'lang_source': langSource,
// we use the second part of the url_parts, the uid itself
'context_uid': url_parts[1]
};
var targetelement = destination_field.find('textarea');
var tiny_editor = destination_field.find("textarea.mce_editable");
if (!targetelement.length) {
Expand Down
13 changes: 12 additions & 1 deletion src/plone/app/multilingual/browser/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from plone.app.multilingual import _
from plone.app.multilingual.interfaces import IMultiLanguageExtraOptionsSchema
from plone.app.multilingual.interfaces import ITranslationManager
from plone.app.uuid import uuidToObject
from plone.base.interfaces import ILanguage
from plone.registry.interfaces import IRegistry
from plone.uuid.interfaces import IUUID
Expand Down Expand Up @@ -57,7 +58,17 @@ def __call__(self):
):
return _("Need a field")
else:
manager = ITranslationManager(self.context)
context_uid = self.request.form.get("context_uid", None)
if context_uid is None:
# try with context if no translation uid is present
manager = ITranslationManager(self.context)
else:
context = uuidToObject(context_uid)
if context is not None:
manager = ITranslationManager(context)
else:
manager = ITranslationManager(self.context)

registry = getUtility(IRegistry)
settings = registry.forInterface(
IMultiLanguageExtraOptionsSchema, prefix="plone"
Expand Down