Managing URL Patterns for Multilingual Websites
Last updated
Last updated
Multilingual modules allow users to configure languages and how page languages are chosen and apply languages to the project entities. Managing URL patterns is one of the main features that will be provided to be controlled and updated by Administrators.
Multilingual websites have further options for URL/path aliases. This section shows how URL patterns for multilingual websites in Varbase can be configured.
There are three ways to implement that:
In Varbase, URL aliases will be automatically generated regarding specified tokens, ex: [node:title] for landing pages.
To test that follow the steps below:
Navigate to Manage \ Add content \ Landing page (with layout builder).
Fill in the Title field, ex: About Us.
Check the URL alias option in the settings.
Result: URL aliases are checked to be automatically generated using a token, and in this case, the node title is the token. So the URL alias for the page will be /node-title, ex: /about-us.
Patterns for each entity/content type on the site can be seen here, for example, the Hierarchical paths for Landing pages (Layout Builder) label is responsible for the URL pattern for the Landing page (Layout Builder) content type, the default pattern for this content type consists of two tokens [node:menu-link:parents:join-path]/[node:title]. The first token will grab the parent item for the page specified when providing a menu link, the second token will grab the title of the page being edited.
In case no parent item is provided, the first token will be ignored.
To show another example with hierarchy, we will create a landing page and add it as a child for a parent in the menu.
Navigate to Manage \ Add content \ Landing page (with layout builder).
Fill the Title field, ex: Our Team.
Check the Menu settings option.
Fill in a menu link title and select a parent for this landing page.
Now, check the URL alias value.
Result: URL alias will be /parent-name/node-title, ex: /about-us/our-team.
Hint: Patterns can be added/updated by clicking on Configure URL alias patterns or by navigating to Administration \ Configuration \ Search and Metadata \ URL aliases \ Patterns. To learn more about configuring URL aliases, check the following documentation.
First, we need to extend the needed multilingual modules - In Varbase we have them by default.
Navigate to Manage \ Extend.
Scroll down for the Multilingual section.
Verify that the following modules are enabled:
Configuration Translation
Content Translation
Interface Translation
Language
Along with that, we need to enable the following module - filter for “language” for faster results:
Varbase Internationalization
Hint: Typically developers will enable those modules during installation. For further information click here.
Navigate to Configuration \ Regional and Language \ Languages.
List tab will show the available languages and the default language for the website with the ability to add new languages as well.
The Detection and selection tab has URL settings to configure the language URL pattern to be a prefix or a domain.
Click on Configure next to URL under the Detection and selection tab.
Option1 - URL prefix
When the option of “URL prefix” is selected you will find that the language prefixes are following the domain name, ex: https://{domain}/en for the English language, and https://{domain}/ar for the Arabic language.
Option2 - Domain
When the option of “Domain” is selected, you will be able to add different domain names for different languages with no language prefix, ex: https://english-version.com.
Hint: “URL prefix” option is selected by default in Varbase.
The same entity can be translated to different languages regarding the selected settings that were explained earlier.
We can select a content entity to translate to check the URL alias for the translated node.
Navigate to Manage \ Content.
Select a landing page and click on edit.
Switch to the translate tab.
Add a translation for the selected page.
Click on Save.
URL aliases for the translated pages can be applied in different ways as mentioned before, and we will go through them in detail.
Hint: All created entities should have specific language (not neutral), so the translate option could be displayed for those entities.
This option will make the URL have the text of the native language of the page, this will allow the URL to have non-ASCII characters, it can include characters from any language.
To have the native language URL pattern enabled, the Transliterate prior to creating aliases option should be disabled, this can be done by following the steps below:
Navigate to Administration \ Configuration \ Search and Metadata \ URL aliases \ Settings.
Uncheck the option Transliterate prior to creating aliases.
Save the configurations for the URL aliases setting.
When creating/translating content, the URL to that content will include the characters of the language of that content title.
Hint: In Varbase, this is the default option for multilingual URL patterns. So no need to update anything there.
Example:
https://www.unicef.org/ website is using “Native Language URL Patterns” so the URL alias will change regarding the selected language for the same page. So for “What to Do” page as an example, the URL aliases would be:
https://www.unicef.org/what-we-do for the English version
https://www.unicef.org/fr/ce-que-nous-faisons for the French version
Pros & Cons
Pros:
Fully automated. No need to write manually a specific URL. It will be auto-generated from the page/content title or whatever you specify as a token for the URL.
There's an SEO aspect for keywords in URL (you need citation here).
Cons:
Copying/pasting or sharing non-ASCII characters makes it encoded and not easy to share.
This option will force the source (default) language URL aliases to be applied to all languages, so if you want the English version then the default language should be English, however, if the default language was not the English language then the URL alias patterns will follow the source language. The only thing that will be changed is the language identifier that can be either a prefix or a domain as explained earlier.
To configure Base-Language only URL patterns, we need to change the tokens that were used in the added URL aliases by following the steps below:
Navigate to Administration \ configuration \ Search and Metadata \ URL aliases \ Patterns.
Select an existing pattern to edit, or you can add a new one.
Click on Browse available tokens.
Search for Translation source node section.
Then copy the correct token from there.
Tokens for landing pages URL alias patterns are using the translated language token by default, however, if we need them to keep using the default language’s aliases we need to update the tokens for landing pages as below:
Menu token
[node:menu-link:parents:join-path]
[node:source:menu-link:parents:join-path]
Node title token
[node:title]
[node:source:title]
Save the configurations and check the URL for any landing page in order to check that it was applied correctly.
Example:
https://www.vardot.com/ website is using “Base-Language Only URL Patterns” for URL aliases, so when we navigate to any page then change the language, the URL alias will stay the same as the source language - which is English in this case- and only the language identifier will change, so as an example we can check “About Us” page:
https://www.vardot.com/en/about-us is the English version.
https://www.vardot.com/ar-jo/about-us is the Arabic version.
Pros & Cons
Pros:
Maintains one URL structure, the only difference is the language code/prefix in the URL.
English-language (or Latin characters) URLs are neatly shared, with no encoding.
Fully automated - but only if your base language (original language) is always the same.
Cons:
You always need a base language (original translation).
You will have to manually write the URL pattern - in case a page did not have a base language that matches your pattern.
Example:
English (source)
example.com/en/about-us
example.com/fr/about-us
French (source)
Needs to be manually edited to get example.com/fr/contact-us
example.com/fr/nous-contacter
This option will convert the translated non-Latin characters to US ASCII characters, so the URL, in this case, will not contain non-English letters.
Transliterated URL alias is a global option for all patterns, which can be configured by selecting the option from settings.
Navigate to Administration \ configuration \ Search and Metadata \ URL aliases \ Settings.
Select Transliterate prior to creating aliases option.
Example:
If a landing page with the title of “About Us” was created then translated to “من نحن” in Arabic, the URL alias for both pages will be as below:
/en/about-us for the English version.
/ar/mn-nhn for the Arabic version.