Revision #9 was created by JQL on Dec 5, 2023, 2:57:36 PM.
Edited title and fixed some typos
Content
# How To Add Internationalisation to the NavBar Menu in Yii2 Basic (Bootstrap 5)
Yii comes with internationalisation (i18n) "out of the box". There are instructions in the manual as to how to configure Yii to use i18n, but little information all in one place on how to fully integrate it into the bootstrap menu. This document attempts to remedy that.
[...]
'Home' => 'Accueil',
'About' => 'À propos', ...
```
## Create a Menu Item (Dropdown) to Change the Language
[...]
A `key` and a `name` is required for each language.
The `key` is the ICU language code in lowercase (with optional [ISO 639.1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) in lowercase (with optional Country code [ISO 3166](https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes) in uppercase) e.g.
> French: `fr` or French Canada: `fr-CA`
[...]
> Portuguese: `pt` or Portuguese Brazil: `pt-BR`
The `name` is the name of the language *in that language*. e.g. for French: `'Français'`, for Japanese: `'日本の'`. *This is important* as the user may not understand the browser's current language.
In `/config/params.php` create an array named `languages` with the languages required. For example:
[...]
```
If countryLanguage flags or images are required next to the language name see *Optional Items* at the end of this document.
### 6. Trigger the Language change with an Ajax call
[...]
To call the Language Action `actionLanguage()` make an Ajax call in a JavaScript file.
Create a file in `/public_htmlweb/js/` named `language.js`.
Add the following code to the file:
[...]
```
**Internationalisation should now be working on your project.**
[...]
```
### 2. Add CountryLanguage Flags to the Dropdown Menu
This is very useful and recommended as it aids the User to locate the correct language. There are a number of steps for this.