First of all, lets understand what is a multilingual website:
Those websites which provide content on its web pages in more than one language are a multilingual website.
Drupal is one of the most popular web CMS (Content Management System) among PHP developers. The new latest released version Drupal 8 is getting more popular and most demanded for its new features added as part of the core platform (for eg. views become part of Drupal 8 core). It also provides better support for multilingual and globalization.
Drupal 8 provides most of the functionality required to build a multi-lingual site by its four modules as part of its core platform. These modules provide the interfaces to easily add languages and to translate content and user interface into different languages.
Add Translation Filter for multilingual functionality in view settings:
When we create blocks and pages using views with default settings display content in the default language (selected during installation). In multilingual sites, the same content is translated into multiple languages, so there are multiple translated versions of content stored in the database. Drupal provides filters which can be used to filter, and display the content added in a specific language. Without the use of these filters the view pages render the same content added in all languages irrespective of the selected language.
Let's see this with an example below "problem statement":
The above image shows an example in which we added content in two languages (English and Hindi) and creates a page using a view to show the list of recently added content. We also add language switcher in the left sidebar to display content in the selected language. As we can see that currently English is selected, but the page displays the same content in both English and Hindi language, to get rid of this issue follow the below steps.
How to apply translation filters with the view to filter multilingual content?
Drupal provides different filters for applying filtering of content on the basis of different conditions. We can easily resolve the above issue by applying translation filters on "views". Below are the steps to add and apply filters to view in Drupal 8:
Step 1: In view interface, click on ADD button to add new filters
Step 2: We can apply filters in following two ways:
(i) By adding Translation filter
- After clicking Add button in Step 1, choose "Content" from the Category dropdown list.
- Scroll down the list of filters to find "Translation Language" or type the name on Search textbox.
- Check the checkbox to select the filter and click the below button "Add and configure filter criteria".
- Select "Interface text language selected for the page" from Language list and click on "Apply" button.
(ii) By using Rendering Language:
- This is another way to apply translation filters for views. By default, the Rendering language to view is set as "Content language of view row".
- Click on the link "Content language of view row" and select "Interface text language selected for the page" from Rendering Language dropdown list and click on Apply button.
- Click on Add button to Step 1, and select "Default Translation" filter under Content category and click on Apply button.
- Select "True" for Default translation.
Step 3: To apply these filters on view, click on the Save button.
After applying these filters we get the below result.
In the above image we can see that after applying filters, the filtered result only display the list of contents in English (selected language). Same like this if we select the Hindi language from sidebar the page displays the translated version of the content in the Hindi language.
0 Comment(s)