0

I have a multi-language site.

How this is supposed to work is that on /fr pages, everything except main navigation block should be in French. However, main navigation menu block should be in whatever currently logged user's language.

I tried to change language code in custom module using block or menu hook, but none of them worked.

Thanks in advance.

0

You don't need a custom module for this.

Drupal can have seperate language detection for interface (menu item/interface elements) and content. There was a bug that was fixed recently so make sure you are on the latest 8.6.x version.

Assuming you have enabled all 4 core language modules and you have enabled at least 1 extra language than configure the language detection methods to accomplish what you want as I its outlined below.

Go to Configuration > Regional and language > Languages > Detection and selection and

  • enable Account administration pages. This will allow each user to choose their preferred interface language (there will be a new option when they edit their profile page) enter image description here
  • enable content language detection. This will make available the language switcher (content)) block.
  • enable 1 detection method. In my case I choose url (i.e. /en /fr) but you can choose any other or more methods if you like.

ΝΟΤΕ: The detection methods take precedence as they appear from top to bottom provided they are also enabled.

enter image description here

Go to Structure > Block layout and enable language switcher (content) (not language switcher (interface text)

Now lets say a user has chosen English as their interface language they can press on the language switcher (content) and their interface (menu, admin menu etc) will always stay English.

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.