2

I have a multilingual site.

I want it so that if a user has chosen French as they preferred language, but no French translation exists for a particular page, then an automatic Google Translation is displayed.

I have tried doing things like installing the Google website translation module: https://translate.google.com/manager/website/ but this of course cannot display the proper translation if one exists because it does not integrate with Drupal. I have also looked at options like GTranslate https://www.drupal.org/project/gtranslate, which has a Drupal module but that does not integrate properly with Drupal multilingual sites.

Any suggestions for a solution to this? The only way I can think of doing it is to The Translation Management Tool (TMGMT) module and to use Google translate all pages and have those Google translations as proper Drupal translations, although this has disadvantages as well in that it will be cumbersome to do with this hundreds of pages. Any ideas?

  • Drupal 6? Since the module you mentioned only has 6er release. – leymannx Jan 13 '17 at 15:34
  • Depending on how professional you want to be, don't... I have tried the same approach for some English > Dutch translations and Google translate messed them up. In the end it turned out our users preferred reading the English text rather than the crooked Dutch version. In our case it decreased the user experience. – Neograph734 Jan 13 '17 at 15:56
  • Sorry, it's Drupal 8, I put the wrong link in above, I have corrected it. – James Jan 13 '17 at 16:58
  • Neograph734 - I agree! Unfortunately the client demands this. – James Jan 13 '17 at 17:00
1

I have an idea that we can achieve using gtranslate language dropdown (hidden) and drupal langauge dropdown

Steps in hook_preprocess_page check node has translation if yes make the page is not google translatable using class "notranslate" if it has not translation then pass the language code to javascript and call google translate function

For Exampel: /** * Implements hook_preprocess_page(). */ function hook_preprocess_page(&$variables) { $variables['attributes']['class'] = []; $language = \Drupal::languageManager()->getCurrentLanguage()->getId();

$variables['attributes']['class'][] = 'node-' . $nid;

if(isset($variables['node'])) {
    $nid = $variables['node']->id();

    if($variables['node']->hasTranslation($language)) {
        $variables['attributes']['class'][] = 'notranslate';
    }
    else {
        $variables['#attached']['drupalSettings']['language'] = $language;
    }
}

}

In Custom.js

doGTranslate('en|' + drupalSettings.language);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.