0

I have to put a several languages in a site. But I just discovered that the taxonomy terms without a language (because it's the same label for every language) gives the link toward a page in the default language on the site. On the other hand, taxonomy vocabularies that have translations work fine. Just the taxonomy vocabularies without translation (and no language defined) give me troubles.

So when you click on a taxonomy term in the default language (French), you go to the French taxonomy term page. When you click on the taxonomy term in Chinese, you still go to the French taxonomy term page.

I don't understand why and I seek a way to fix the problem.

I tried using {{language}} in the template, so I could add the language code prefix to the link, but it renders nothing.

I added the following preprocess function, but using {{ language }} in the template still doesn't render anything.

function gavias_monte_preprocess_page(&$variables) {
  $language = \Drupal::languageManager()->getCurrentLanguage()->getId();
  $variables['language'] = $language;
}
  • Did you rebuild the cache after adding the hook? – Clive May 17 '17 at 13:47
  • Yes I did it several times during my test... I rebuild each time I modify templates, routes, ... – Erik May 17 '17 at 13:56
  • put dpm('test') inside the function and go to visit a page you should see 'test' if not your hook is not called. Do this and let my know the result. – Adrian Cid Almaguer May 17 '17 at 14:31
  • With dpm('test'); & dpm($language); I got "test" and the right language code in the page as a DSM. But in Twig, {{ language }} still render nothing ! Weird ! In Twig {{ language }} I got DSM of "test" and "zh-hans" who is the code for chinese. But nothing using {{ language }} Weird ! Of course I tried several time and rebuild cache each time (we never know). But nothing ! – Erik May 18 '17 at 7:28
0

I though that using mymodule_preprocess_page will modify all pages (as DSM was working everywhere). Seems not for the variables... I tried mymondule_preprocess_node but it crashes the site. So I tried this...

function gavias_monte_preprocess_node__lieu__full(&$variables) {
    $language = \Drupal::languageManager()->getCurrentLanguage()->getId();
    $variables['language'] = $language;
}

To my surprise it works. But that means I pass the language (and any other kind of variables) just for this specific template.

| improve this answer | |

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.