- Issue created by @wouters_f
- 🇱🇹Lithuania mindaugasd
Related issue where this was discussed in the past: ✨ Add support for language translation, and non-English languages Active
- 🇧🇪Belgium wouters_f Leuven
So it works now.
This is the translation screen if translations is enabled for the Content type.
This is how it looks after the Translation.
Remarks
tested with
- Openai: Works
- Mistral: Does not work
- 🇧🇪Belgium wouters_f Leuven
@Marcus: I'm not sure why the Mistral integration throws this error
PHP message: Uncaught PHP Exception TypeError: "array_map(): Argument #2 ($array) must be of type array, null given" at /var/www/html/vendor/openai-php/client/src/Responses/Chat/CreateResponse.php line 49
- Status changed to Needs review
7 months ago 12:36pm 26 June 2024 - 🇧🇪Belgium wouters_f Leuven
The Mistral API errors were not caught by the underlying library.
It did not have to do with the translations. - 🇬🇧United Kingdom yautja_cetanu
Very cool! I wonder if it should be under an examples or just a submodule
- 🇧🇬Bulgaria valthebald Sofia
I would vote for submodule (and agree with @wouters_f that this should be the core feature for editors)
- 🇧🇪Belgium wouters_f Leuven
I created it as a submodule.
In my opinion this is a very valid separate module :D.
I organised my code also like this. - 🇧🇬Bulgaria valthebald Sofia
Hey @wouters_f,
First of, thanks for the submodule, that would help a lot of people!
Some notes/questions though:- Passing both lang_code and lang_name in ai_translate.translate_content route seems redundant. Can be only lang_code?
- Instead of lang_name, I would pass entity_type parameter, allowing to translate not only nodes, but other content entities as well. Logic can be similar to core's Drupal\field_ui\Routing\RouteSubscriber::alterRoutes(), that basically attaches to most content entity types.
- Another parameter that I would add is source_lang. For longer texts this may be less relevant, since it's easier to guess from the context, but for shorter ones would be less easier to prompt "as a helpful translator, translate from ... to ..."
- Permission "access chatgpt translation" should have more generic name, i.e. "access ai translation" or (following core pattern) "create ai content translations". There are some other mentions of chatgpt in the code, but given AiTranslateController uses default provider, I assume the code is provider-agnostic
What do you think?
If you agree with any point, I'd be glad to help (then I'll need permissions on the issue branch) - 🇩🇪Germany marcus_johansson
To add to @valthebald great comments - if we add source language we could also add a generic operation type for translation. Since deepl, Grammarly and some other services offers none-LLM, but AI powered translations these would be very simple to add support for these services for any module to use.
This makes this module more flexible and the AI module more comprehensive.
So you would do:
$input = new \Drupal\ai\OperationType\Translate\TranslateInput('How do you do?', 'de', 'en'); $translation = \Drupal::service('ai.provider')->createInstance('deepl')->translate($input)->getNormalized(); // $translation would be a string "Wie geht es dir?".
This would take 1 hour to add and maybe 1-2 hours to add those two plugins.
Another comment on this in general is that we should perhaps notice which LLM's actually are ok with translating and to which languages. If you do gemma-2b for instance it can't really translate almost anything, while OpenAI is generally even better than Deepl at certrain languages.
- 🇬🇧United Kingdom yautja_cetanu
I wonder if it's worth putting in a setting for "Context" for specific languages so that the pre-prompt can be edited at all for a specific language. So when you are translating from American English to Swedish, the site owner can choose to make it translate the tone or make it a word for word translation?
This could be optional settings to make it a little more useful?
I would eventually like any modules like this in core to work with the future evaluations module.
- Status changed to Needs work
7 months ago 7:43pm 8 July 2024 - 🇧🇪Belgium wouters_f Leuven
I agree those would be nice things.
I just wanted to provide a lift and shift from the chatgpt_plugin to this module to provide them an easy switch with similar behavior.
Personally I think supporting paragraphs ( https://www.drupal.org/project/chatgpt_plugin/issues/3456725 ✨ Add support for paragraphs in translations Needs work ) which is a feature they request is more important for the adoption (and even adding layout builder to that too).From what I see the 141 sites that use chatgpt_plugin have no issues with the detection of language, there's no bugs regarding this (yet?).
I would log these things as separate improvements to the translation module which we could work on later (if found of importance).
Also I personally don't know (yet) how to add these plugins (coding is rusty sorry).So I think if we lift and shift the as is, we're already doing a great job and we could pull in the 141 sites using chatgpt_plugin.
Anything extra is nice, but in my opinion extra. - Status changed to Needs review
7 months ago 2:36pm 9 July 2024 - 🇧🇬Bulgaria valthebald Sofia
As I said, I'd be glad to help when it comes to the coding part :)
Suggested changes are not that big to postpone them - Status changed to Needs work
7 months ago 2:37pm 9 July 2024 - Status changed to Needs review
7 months ago 8:51pm 10 July 2024 - 🇧🇬Bulgaria valthebald Sofia
I've submitted my suggestions from #12:
- Removed node as hard-coded entity type, expecting ContentEntityInterface now. AiTranslateRouteSubscriber::alterRoutes() was already adding "Translate with AI" links to all supported entity types.
- Changed signature of AiTranslateController::translate() to AiTranslateController::translate($entity_type, $entity_id, $lang_from, $lang_to)
- Changed permission name to "create ai content translation" and added module's .permissions.yml
- Enabled translation from original to default language (entity is not necessarily created in site default language, but it would be good to have an option to translate from original language to default one)
Performed several tests locally, module worked for me for both nodes and taxonomy terms
Things that are not working yet:
- The only supported base field is label
- All fields are treated as text_format (value + format), including plain text
Both issues do not look to me as deal breakers to include the module to HEAD, but up to you to decide.
- Status changed to RTBC
7 months ago 7:12pm 12 July 2024 - 🇩🇪Germany marcus_johansson
Thank @valthebald and wouters_f - the code in the module looks great now and I have tested it on combinations of Swedish, English, German and Japanese and with OpenAI GPT-4o it works great.
I would say we merge it with dev, unless someone is opposed to it being part of AI and should be a contrib module?
- Status changed to Needs work
6 months ago 5:03pm 15 July 2024 - Status changed to RTBC
6 months ago 7:11am 16 July 2024 - 🇧🇪Belgium wouters_f Leuven
ok so I added the requirements hook and now propose to close/merge the ticket now.
- Status changed to Needs work
6 months ago 7:48am 16 July 2024 - 🇩🇪Germany marcus_johansson
I posted two minor change requests, after that hopefully all is done.
- Status changed to Needs review
6 months ago 2:37pm 16 July 2024 - 🇧🇪Belgium wouters_f Leuven
Worked on these last ones...
https://git.drupalcode.org/project/ai/-/merge_requests/10 - Status changed to RTBC
6 months ago 7:39am 17 July 2024 - 🇩🇪Germany marcus_johansson
Tested and rewritten certain parts. Unless someone opposes it, it will be merged tonight CET.
-
Marcus_Johansson →
committed e30cb035 on 1.0.x authored by
valthebald →
Resolve #3457200 "Ai translations submodule"
-
Marcus_Johansson →
committed e30cb035 on 1.0.x authored by
valthebald →
- Status changed to Fixed
6 months ago 8:57am 18 July 2024 -
Marcus_Johansson →
committed e30cb035 on ai-search authored by
valthebald →
Resolve #3457200 "Ai translations submodule"
-
Marcus_Johansson →
committed e30cb035 on ai-search authored by
valthebald →
-
Marcus_Johansson →
committed e30cb035 on ai-assistants authored by
valthebald →
Resolve #3457200 "Ai translations submodule"
-
Marcus_Johansson →
committed e30cb035 on ai-assistants authored by
valthebald →
-
Marcus_Johansson →
committed e30cb035 on ratelimit-quota-exceptions authored by
valthebald →
Resolve #3457200 "Ai translations submodule"
-
Marcus_Johansson →
committed e30cb035 on ratelimit-quota-exceptions authored by
valthebald →
-
Marcus_Johansson →
committed e30cb035 on 3462123-add-access-check authored by
valthebald →
Resolve #3457200 "Ai translations submodule"
-
Marcus_Johansson →
committed e30cb035 on 3462123-add-access-check authored by
valthebald →
- 🇮🇳India anup.sinha Bengaluru
Hi @wouters_f, thanks for porting the translation component from my Drupal OpenAI plugin - https://www.drupal.org/project/chatgpt_plugin → . Let us all work on the patch to provide support for Paragraphs module.
- 🇳🇱Netherlands jurriaanroelofs
Have you considered integrating with the TMGMT framework? It's a very powerful suite for both human and AI translation and it is very extensible, too.
- 🇧🇪Belgium wouters_f Leuven
Hi JuriaanRoelofs,
This module is a simple translation integration. The goal was here to be as independant as possible as many multilingual sites are not using tmgmt yet (in our company).
But I fully agree there should be a version of https://www.drupal.org/project/tmgmt_openai → that does this.
I think it would make perfect sense for them to also use the AI module under the hood.
It could even be a separate ai_tmgmt module where this is abstracted away from openai. - 🇳🇱Netherlands jurriaanroelofs
Got it, yeah I agree on all of that too :) We all should be making modules that abstract away from any single LLM service provider.
- 🇧🇬Bulgaria valthebald Sofia
@anup.sinha that was the first thing on my mind after seeing initial patch :)
I believe we should have a separate issue for that - 🇧🇬Bulgaria valthebald Sofia
...and it exists, actually! ✨ (ai_translate) One click translations for Paragraphs Needs review
Automatically closed - issue fixed for 2 weeks with no activity.