- 🇧🇪Belgium Amedee
The problem is that the module assumes that the original page is in English, and won't initially offer to translate in the current language.
Once you select another language, the page is no more in English, so it will appear in the selector.I fixed it by hard-coding my site language in google_translator.module (French in my case):
164 unset($active_langages[0]); 165 if (!empty($active_langages)) { 166 $display_mode = variable_get('google_translator_active_languages_display_mode', ''); 167 $display_mode = !empty($display_mode) ? 'layout: google.translate.TranslateElement.InlineLayout.' . $display_mode : ''; 168 $default = "<span id='google_translator_element' class='google_translator'>{$close}</span><script>function googleTranslateElementInit() { 169 new google.translate.TranslateElement({ 170 pageLanguage: 'fr', // <-- set site language here 171 includedLanguages: '" . implode(',', array_keys($active_langages)) . "'," . $display_mode . " }, 'google_translator_element');}</script> 172 <script src='//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit'></script>"; 173 } 174 return $default; 175 }
Ideally this should be a module configuration parameter
I have developed a patch.
Drupal::languageManager()->getCurrentLanguage()->getId()
gets the current language code of the website. This can be passed todrupalSettings.googleTranslatorElement
and used aspageLanguage
for the newTranslateElement
.It would also be possible to leave
pageLanguage
undefined
. Then google tranlsate will automatically set the source language.- Status changed to Needs review
over 1 year ago 10:35am 7 July 2023 - 🇩🇪Germany JoCowood Kamp-Lintfort
Based on the patch from #7 I developed a patch which uses dependency injection instead of the static Drupal::languageManager() call. Since Tenguiz has found the actual solution to the problem please give credit to him (also?).
- 🇮🇳India sahil.goyal
Provided Patch #9 resolving the issue as google translator list eng. not shown at first shot, now after the patch in the dropdown selector show English option at first when Spanish language enabled firstly.
RTBC+1 - 🇩🇪Germany JoCowood Kamp-Lintfort
Can someone please review this and set the issue to "Reviewed & tested by the community"?
- Status changed to RTBC
about 1 year ago 11:11am 30 August 2023 -
jenna.tollerson →
committed 88bd3f8a on 2.x authored by
JoCowood →
Issue #3078892 by JoCowood: English language is not shown at first shot
-
jenna.tollerson →
committed 88bd3f8a on 2.x authored by
JoCowood →
- Status changed to Fixed
9 months ago 9:52pm 20 February 2024 - 🇺🇸United States jenna.tollerson Atlanta, Georgia, USA
This is really great work, I appreciate it, y'all. Thanks!
Automatically closed - issue fixed for 2 weeks with no activity.