Skip to content

Commit 9c0275f

Browse files
authored
Merge branch '6.0' into maurits-start-upgrade-guide-plone-62
2 parents b5e54f4 + 707b149 commit 9c0275f

File tree

3 files changed

+55
-76
lines changed

3 files changed

+55
-76
lines changed

docs/_static/translate.svg

Lines changed: 4 additions & 0 deletions
Loading

docs/backend/upgrading/version-specific-migration/upgrade-to-62.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,24 @@ This is because we keep a mapping from the old to the new location.
8181
For example, `plone.locking` registers that `plone.locking.browser.info.pt` has a new location: `plone.app.layout.viewlets.locking.pt`.
8282
You should rename your override to the new location if you no longer need compatibility with Plone 6.1 or earlier.
8383
```
84+
85+
86+
## Replaced Google Translate integration with generic translation integration
87+
88+
`plone.app.multilingual` had an integration to use only Google Translate to translate the content in the `babel_view`, where the content in two languages is shown side-by-side.
89+
This integration was limited to only Google Translate.
90+
In Plone 6.2, this integration has been replaced with a generic translation service integration hook.
91+
92+
[`collective.translators`](https://github.com/collective/collective.translators) provides some implementations for that hook, supporting AWS, Deepl, Deepseek, Google Translate, Libre Translate, and Ollama.
93+
It can be extended to support more translation providers.
94+
95+
It is not mandatory to use `collective.translator`.
96+
Any developer can write the integration with the tool of their choice.
97+
98+
See the {doc}`/i18n-l10n/use-an-external-translation-service` chapter for details.
99+
100+
To achieve that integration, the previously existing `gtranslation_service` browser view has been removed from `plone.app.multilingual`.
101+
102+
Due to not needing it anymore, the `plone.google_translation_key` registry entry has been removed, and it will be removed when performing the upgrade step to Plone 6.2.
103+
104+
The `babel_view` has been modified to call a new REST API endpoint instead of the old `gtranslation_service` browser view.

docs/i18n-l10n/use-an-external-translation-service.md

Lines changed: 30 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -14,88 +14,42 @@ myst:
1414
When translating content items in Plone, you can connect to an external translation service to translate your content.
1515

1616

17-
## Using Google Cloud Translation API
17+
The `plone.app.multilingual` product that turns Plone into a multilingual content site supports a pluggable way to hook any translation service into Plone.
1818

19-
The `plone.app.multilingual` product that turns Plone into a multilingual-content site supports [Google Cloud Translation API](https://docs.cloud.google.com/translate/docs/reference/rest), which allows the content editor to use its translations.
19+
To do so, one has to implement a utility that implements an `IExternalTranslationService` interface.
2020

21-
To use this service as a site administrator, you need to create a project in Google Cloud, enable the Cloud Translation API, and create an API key under the Credentials of the Google Cloud Console.
22-
You should enter this API key in the {guilabel}`Multilingual Settings` control panel in Plone.
21+
This utility class must implement the `IExternalTranslationService` interface from `plone.app.multilingual.interfaces` and it should provide at least these methods and an attribute:
2322

24-
After doing so, as a content editor, when you edit a translation of a given content page, an icon will display next to the original content.
25-
When you click this icon, it invokes the Google Cloud Translation API, and the translation obtained through the service will be entered automatically in the corresponding field.
23+
`is_available()`
24+
: Returns `True` if the service is enabled and ready.
2625

27-
```{note}
28-
The usage of Google Cloud Translation API may create extra cost for the site administrator.
29-
See [Cloud Translation pricing](https://cloud.google.com/translate/pricing) for details.
30-
```
26+
`available_languages()`
27+
: Returns a list of supported language codes or pairs that can be used (source, target).
3128

29+
`translate_content(content, source_language, target_language)`
30+
: Performs the translation and returns the translated text.
3231

33-
## Using other translation services
34-
35-
If you want to use another service beside Google Cloud Translation API, you will need to override the view that calls Google Cloud Translation API.
36-
37-
To do so, `plone.app.multilingual` registers a view called `gtranslation_service`.
38-
Its code is in [`plone.app.multilingual.brwoser.translate.gtranslation_service_dexterity`](https://github.com/plone/plone.app.multilingual/blob/7aedd0ab71d3edf5d1fb4cb86b9f611d428ed76b/src/plone/app/multilingual/browser/translate.py#L52).
39-
This view gets three parameters:
40-
41-
`context_uid`
42-
: The UID of the object to be translated.
43-
44-
`field`
45-
: The name of the field of the object that needs to be translated.
46-
This view's job is to extract the value of that field from the object.
47-
48-
`lang_source`
49-
: The source language code.
50-
51-
The first part of the view—that which gets the object and the field content to be translated—can be copied from the original code.
52-
You need to write only the call to the translation service.
53-
The required code would be something like the following example:
54-
55-
```python
56-
class TranslateUsingMyService(BrowserView):
57-
def __call__(self):
58-
if self.request.method != "POST" and not (
59-
"field" in self.request.form.keys()
60-
and "lang_source" in self.request.form.keys()
61-
):
62-
return _("Need a field")
63-
else:
64-
manager = ITranslationManager(self.context)
65-
context_uid = self.request.form.get("context_uid", None)
66-
if context_uid is None:
67-
# try with context if no translation uid is present
68-
manager = ITranslationManager(self.context)
69-
else:
70-
catalog = getToolByName(self.context, "portal_catalog")
71-
brains = catalog(UID=context_uid)
72-
if len(brains):
73-
context = brains[0].getObject()
74-
manager = ITranslationManager(context)
75-
else:
76-
manager = ITranslationManager(self.context)
77-
78-
registry = getUtility(IRegistry)
79-
settings = registry.forInterface(
80-
IMultiLanguageExtraOptionsSchema, prefix="plone"
81-
)
82-
lang_target = ILanguage(self.context).get_language()
83-
lang_source = self.request.form["lang_source"]
84-
orig_object = manager.get_translation(lang_source)
85-
field = self.request.form["field"].split(".")[-1]
86-
if hasattr(orig_object, field):
87-
question = getattr(orig_object, field, "")
88-
if hasattr(question, "raw"):
89-
question = question.raw
90-
else:
91-
return _("Invalid field")
92-
93-
# And here do the call to the external translation service
94-
return call_to_my_service(question, lang_target, lang_source)
95-
```
32+
`order`
33+
: The order in which this utility will be executed.
34+
This way, one can prioritize some services over others with given conditions.
35+
36+
After doing so, as a content editor, when you edit a translation of a given content page, a translate icon <img alt="Translate icon" src="../_static/translate.svg" class="inline"> will display next to the original content.
37+
38+
When you click this icon, it will invoke the translation utility, and the translation obtained through the service will be entered automatically in the corresponding field.
39+
40+
Plone does not implement this interface by itself in any of its utilities.
41+
42+
You'll need to use an external package that offers this service as described in {ref}`pre-configured-services-label`, or create your own utility.
43+
44+
(pre-configured-services-label)=
45+
46+
## Using the translation service with pre-configured services
47+
48+
To use some external tools, the Plone community has implemented a package called [`collective.translators`](https://github.com/collective/collective.translators) that implements this functionality for AWS, Deepl, Deepseek, Google Translate, Libre Translate, and Ollama.
49+
50+
Each of those services provides a control panel to tweak the configuration, including API keys, languages, service endpoints, and other configuration items.
9651

9752
```{note}
98-
Due to the way that the Google Translate integration is built in `plone.app.multilingual`, you will need to enter something in the {guilabel}`Google Translate API Key` field in the {guilabel}`Multilingual Settings`
99-
control panel of your site.
100-
It doesn't need to be a valid Google Translate API Key; it can be a random string.
53+
The usage of some of those services may create extra cost for the site administrator.
54+
Check the terms of use of each of the tools for details.
10155
```

0 commit comments

Comments
 (0)