English language is not shown at first shot...

Created on 3 September 2019, about 5 years ago
Updated 5 March 2024, 9 months ago

My site has only Spanish language enabled.

When I've enable this module and place the translation block, it show some languages to translate (French, etc.). All but English. If I select one of them, then, AFTER IT, with the new ONLY PARTIALLY translated page, the dropdown selector show English option. And this is the only one translation option that translate all my page text. All the others just translate some words... attaching screenshots for reference.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇧🇶Caribbean Netherlands calbasi Catalonia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇧🇪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

  • 🇺🇸United States jenna.tollerson Atlanta, Georgia, USA
  • I have developed a patch.

    Drupal::languageManager()->getCurrentLanguage()->getId() gets the current language code of the website. This can be passed to drupalSettings.googleTranslatorElement and used as pageLanguage for the new TranslateElement.

    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
  • 🇩🇪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
  • Status changed to Fixed 9 months ago
  • 🇺🇸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.

Production build 0.71.5 2024