How to translate menus and views (blocks)

Dear colleagues

I have lots of problems with the translation, I don’t know if I have well configured the modules and activated the good modules.

Concerning menus:

  • it seems I have to follow some steps as for example:
  1. translate the content type
  2. translate the menu item
  3. add the correct link to the translated content type
    Is it OK?

Concerning views with entity references:

I have created a view (block) that is displayed in a specific basic page A, a list of basic pages (as preview cards format: B, C, D).
The basic pages B, C, D have a entity reference field who references to the basic page A (parent page).
The view works properly however the problem appears with the translation of the basic pages.

When I have translated the basic pages the view displays duplicated pages.
I have already configured the LANGUAGE field in the view as Interface text language selected for page.
Nothing work …
In my opinion is a problem with the translation…
Could you please help me with this?

Website: https://test-chis.web.cern.ch/
View: https://test-chis.web.cern.ch/admin/structure/views/view/pages_with_buttons/edit/page_1

Screenshot:

Hello Almudena,

I am answering your questions inline.

Menu translation

First of all you should enable a second language and set your content type as translatable. The content type should not necessarily be translated (Names of fields etc). However what you should translate are the nodes.

In other words the logic is the following:

  1. You create a node
  2. You create a menu that points in this node
  3. You translate the node from the translation interface


(In this example you have set it correctly)

  1. You translate the menu item

    51

In this example you have also set it correctly. However I noticed that you have hardcoded the URL. A better practice is to find the node in the “Lien” box and point to the node itself. Why? Because if you change the URL, Drupal will be keep pointing to the wrong URL if you havent set a redirection from the old URL to the new one. On the other hand if you set a pointer to the node, then Drupal will automatically change your menu item and you don’t have to remember where you have hardcoded the menu item.

In general your menu structure and translation looks correct. Do you have an example where it doesn’t work?

View translation

Regarding using block view

Before the translation translation issue I have a comment in the specific view that you mention. Do you have a specific reason why you use a block view and not a page view?

In general use a block view whenever you want to re-use the same block in different pages. If you want to re-use it then obviously your configuration is correct, but it doesn’t seem like a re-usable case. In general you shouldn’t use block views when it is not necessary because block views are highly dependable to the block settings and if the settings are not correct your block might randomly start appearing in pages that it shouldn’t.

If you did it for the header above, then you can just create a view page and just add a Header in the view (its a view configuration) with the text above.

Regarding using Grid as Format

Recently we pushed a new version of the Display Formats, which introduced the Card Grid display format. You might consider using it because the plain Grid Format is not responsive.

Regarding view translation

In order for the view content to appear translated you need to add the Translation language filter in the Filter Criteria of the view.

In the filter settings check the Language to be one of the Interface text language selected for page. What this filter does is that it filters and displays only the nodes that have a translation to the language that you are currently in.

Let me know if that answers your question and sorry for the long answer.

Kostas

Thanks a lot for the answer.
Regarding the Menu, I have already followed the steps that you mentioned, I would like to confirm them. About the URL harcoded was only for test reasons… thanks :slight_smile:

Regarding the view I will implement the filter regarding the languages and I will see.
Thanks again for your help.
regards
Almudena

Hi
Sorry to barge in, but I’m interested in the topic and I am afraid I didn’t quite understand the procedure.

In particular I’d like to take my website, made of a few pages (nodes?), some basic and some landing; and translate it (into Italian); and thus create a parallel site. Ideally one would switch from one site to another with one “language” tab. Or do so page by page. E.g. one could land always on the English page and then be able to switch to the Italian version of it.

Is this all possible in whole or in part? And how does it fit what discussed above?

thanks, Giuseppe

Hi
Yes it is related.
It is possible to add a block called language switcher that changes from one language to another the website.
In my case it works now properly you can have a look in: https://test-chis.web.cern.ch
The menus, blocks, views, content is displayed in English and French (depending on the language selected by the user)
Regards
Almudena

1 Like

Thanks Almudena, your website is very well crafted! It’s just what I’d need
However, pardon my ignorance: I do not understand what I have to do. What do you mean by "add a block called language switcher "?
Can you tell me what I have to do, possibly step-by-step? I have no clue which of the many many options to go through

Thanks and sorry for me being so dumb, Giuseppe

Dear Giuseppe
I will try to explain how I did:

  1. Enable and configure the language module


  2. Add the block Language switcher in order to avoid the user to select the preferred language


I am not an expert but according with my experience the website must be created in one language first and do the translation at the end.
For that you must enable the possibility to translate any entity (examples: nodes, menus, taxonomy, etc…)
Here you are an example of basic page that can be translated.

To do that you must go to the Administration menu, see the image:

I hope that this explanation can be useful and clear.
If you have other question, don’t hesitate to contact me.
regards
Almudena

1 Like