Internationalization (i18n)
Relevant source files
The following files were used as context for generating this wiki page:
The Internationalization (i18n) system in Gauzy is designed to support multiple languages across the user interface, ensuring a localized experience for users worldwide. The system is built upon the popular ngx-translate library for Angular, which facilitates the loading and rendering of translated text.
Translation strings are stored in simple JSON files, with English (en.json) serving as the source language. The translation process is managed and automated through integration with the Crowdin localization management platform. This allows for a streamlined workflow for developers, translators, and project managers to collaborate on localizing the application.
Core Architecture
The i18n system is primarily located in the @gauzy/ui-core/i18n package. It leverages @ngx-translate/core for the translation mechanism and @ngx-translate/http-loader to fetch translation files over HTTP.
Sources: package.json, packages/ui-core/i18n/src/index.ts
Module and Loader
The I18nModule is the central piece of the Angular integration. It configures the TranslateModule from ngx-translate.
TranslateHttpLoaderFactory: This factory function creates an instance ofTranslateHttpLoader, which is responsible for fetching the language-specific JSON files from the/assets/i18n/directory.I18nModule: This module importsTranslateModuleand configures it with theTranslateHttpLoader. It sets up the core translation services and makes them available throughout the application.
The diagram below illustrates how the I18nModule initializes the translation service.
UI Implementation
In Angular components, translations are displayed using the translate pipe provided by ngx-translate. The pipe takes a JSON key as input and renders the corresponding string for the currently active language.
Example Usage in an HTML Template:
<!-- Basic translation -->
<nb-tab tabTitle="{{ 'PLUGIN.DETAILS.OVERVIEW' | translate }}">
...
</nb-tab>
<!-- Translation with a fallback -->
<h5>{{ plugin?.name || ('SM_TABLE.NO_DATA.LOADING' | translate) }}</h5>
This example shows two use cases:
- Directly translating a static key for a tab title.
- Using a translated string as a fallback when a dynamic property (
plugin?.name) is not available.
The following sequence diagram shows the process of rendering a translated string in a component.
Translation Files
Translations are stored in JSON files located at packages/ui-core/i18n/assets/i18n/. Each file corresponds to a specific language, identified by its two-letter ISO code (e.g., en.json, zh.json).
Structure
The JSON files use a nested key-value structure to organize translation strings. This hierarchical organization helps in grouping related translations, such as all button texts or menu items.
Example from en.json:
{
"BUTTONS": {
"SAVE": "Save",
"CANCEL": "Cancel",
"EDIT": "Edit",
"DELETE": "Delete"
},
"MENU": {
"DASHBOARD": "Dashboard",
"SETTINGS": "Settings"
},
"SM_TABLE": {
"NO_DATA": {
"LOADING": "Loading, Please wait...",
"EMPLOYEE": "You have not created any employees."
}
}
}
Sources: packages/ui-core/i18n/assets/i18n/en.json:2-20, 31-35
Supported Languages
The platform supports multiple languages. The full list can be found within the en.json file, which serves as the master list.
| Code | Language Name |
|---|---|
BG | Български (България) |
EN | English (United States) |
RU | Русский (Россия) |
HE | עברית ישראל |
FR | Français (France) |
ES | Español (España) |
ZH | 中文 (中国) |
DE | Deutsch (Deutschland) |
PT | Português (Portugal) |
IT | Italiano (Italia) |
NL | Nederlands (Nederland) |
PL | Polski (Polska) |
AR | العربية (العراق) |
Sources: packages/ui-core/i18n/assets/i18n/en.json:113-127
Translation Management with Crowdin
Gauzy uses Crowdin for localization management. The configuration is defined in the crowdin.yml file at the root of the repository.
Configuration
The crowdin.yml file specifies the source file and the pattern for storing translated files.
project_id: 373243
api_token_env: CROWDIN_API_TOKEN
base_path: '.'
files:
- source: /packages/ui-core/i18n/assets/i18n/en.json
translation: /packages/ui-core/i18n/assets/i18n/%two_letters_code%.json
Key Parameters:
project_id: The unique identifier for the Gauzy project on Crowdin.api_token_env: The name of the environment variable that holds the Crowdin API token.source: The path to the source language file (en.json).translation: The path pattern for where translated files will be placed.%two_letters_code%is a Crowdin placeholder for the language code (e.g.,zh,fr).
Sources: crowdin.yml:1-8
Workflow
The integration with Crowdin automates the flow of strings between the codebase and the translation platform.
This diagram shows the end-to-end translation workflow.
Sources: crowdin.yml
This process ensures that developers can add new text in the source language, and translators can work independently on the Crowdin platform. The synchronized files are then integrated back into the application.
Conclusion
Gauzy's internationalization system is a robust and scalable solution built on industry-standard tools. By using ngx-translate for the frontend implementation and Crowdin for translation management, the platform can be efficiently localized into numerous languages. The clear separation of concerns—developers managing keys and translators managing content—allows for parallel workflows and simplifies the process of maintaining a multilingual application.