Skip to content

Commit

Permalink
Merge pull request #462 from plone/erral-issue-303
Browse files Browse the repository at this point in the history
get the object to be translated correctly in Google Translate view
  • Loading branch information
davisagli authored Oct 2, 2024
2 parents 7aedd0a + 12c3985 commit 419309f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
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]
10 changes: 8 additions & 2 deletions src/plone/app/multilingual/browser/javascript/babel_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,16 @@
original_field.children('.translator-widget').click(function () {
var field = $(value).attr("rel");
// 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
};
'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.utils 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

0 comments on commit 419309f

Please sign in to comment.