The project uses i18n for managing translations. Within the application structure, each section has its own i18n
folder containing YAML translation files. The basic structure is as follows:
src/
└── apps/
├── toolbar/
│ └── i18n/
│ ├── en.yml
│ ├── es.yml
│ ├── fr.yml
│ └── # Other yml translation files...
├── seelenweg/
│ └── i18n/
│ └── # yml translation files...
├── settings/
│ └── i18n/
│ └── # yml translation files...
└── {other}/
└── i18n/
└── # yml translation files...
Each i18n
folder contains YAML files for different languages. The en.yml
file serves as the base for translations, and the other files (es.yml
, fr.yml
, etc.) are updated with translations generated by the script.
The translation script is designed to update translations in YAML files for different parts of the application. It uses the Google Translate API to translate content from English to other supported languages. Below is a detailed explanation of how the script works and how translations are managed.
The script performs the following actions:
-
Loading and Preprocessing:
- Loads the
en.yml
file which serves as the base reference for translations. - Removes keys specified for deletion (
--delete
) and updates keys specified (--update
) in the base object.
- Loads the
-
Object Translation:
- For each language in the list of languages to translate, loads the corresponding YAML file.
- Removes keys specified for deletion and updates keys specified for updating in the translation file.
- Translates the values of the base object to the desired language and updates the translation file with the new values.
-
Saving Translations:
- Writes the updated translations to the corresponding YAML file for each language.
- --delete (or -d): List of keys to be removed from the translations.
- --update (or -u): List of keys to be updated in the translations.
To run the script, use the following command:
npm run translate
npm run translate -- --delete "key1.key2" "key2.other.deep.key"
Where key1.key2
are examples of keys you want to delete or update.
- Automatic Updates: If no arguments are provided, the script will automatically complete missing keys in other languages based on the
en.yml
root file. Existing translations are not overwritten unless specified with--update
. This allows manual modification of translations since they will only be overwritten if explicitly updated.
- Translation API: Translation is performed using the Google Translate API, so an internet connection is required for the script to function properly.
- Manual Corrections: Translations that have been manually corrected by native speakers will not be overwritten unless the
--update
option is used. This feature ensures that manual adjustments to translations are preserved.
For more details on configuring the Google Translate API or adjusting the script, refer to the relevant documentation or contact the development team.