Multi-Language
Support
Considering that there will be users from multiple different countries, you might need to add the support for multiple help you with that, we have made the template compatible with the multiple language functionality.
You can find the dropdown that changes the language in the header.
How does multi-language functionality works?
We have used the packages
@ngx-translate/core and
@ngx-translate/http-loader, you can install it by running the
following
commands in the terminal.
npm install @ngx-translate/core
npm install @ngx-translate/http-loader
You will find language translator logic and design at below given path:
src => app => shared => components => header => widgets => language
Implementing Language Translate Feature
After you finished installing above mentioned packages in your project, follow the below given steps to add the multi-language support.
languages.components.html
Our Html component for language translate will look like this
<div (clickOutside)="hideDropdown()">
<app-button [class]="'btn dropdown-toggle'" [type]="'button'" [id]="'open_dropdown_basic_btn'" [spinner]="false" (click)="openDropDown()">
<span>
<div class="iti-flag {{ selectedLanguage.icon }}"></div> {{ selectedLanguage.language }}
</span>
</app-button>
<ul class="dropdown-menu dropdown-menu-end language-dropdown" [class.show]="active">
@for(language of languages; track language){
<li>
<a href="javascript:void(0)" class="dropdown-item" (click)="selectLanguage(language)" [class.active]="language.code == selectedLanguage.code">
<div class="iti-flag {{ language.icon }}"></div>
{{ language.language }}
</a>
</li>
}
</ul>
</div>
languages.components.ts
Language change logic and configuration:
{
language: 'English', // add laguage name
code: 'en', // add language file code
icon: 'us' // add country
},
JSON files for different languages
JSON files for different languages
To translate words we have to provide the translation for each word, that we will do in a json file.
languages JSON for spanish Language en.json
{
"collections": "Collections",
"collection_layouts": "Collection Layouts",
"collection_left_sidebar": "Collection Left Sidebar",
"collection_right_sidebar": "Collection Right Sidebar",
"collection_no_sidebar": "Collection No Sidebar"
}
languages JSON for spanish Language fr.json
{
"collections": "Collections",
"collection_layouts": "Dispositions des collections",
"collection_left_sidebar": "Collection restante Barre latérale",
"collection_right_sidebar": "Barre latérale droite de la collection",
"collection_no_sidebar": "Collection sans barre latérale",
}
For Example:
Use a variable as follows:
<h4>{{ some_variable | translate }}</h4>
Warning: Make sure that if you are using a variable then you have
added the
translation for every word possible in that variable in the
json file.