Skip to content

Add New Language Support

Bùi Nguyễn Tấn Sang edited this page May 11, 2024 · 8 revisions

Adding New Language Support to Neutron

Neutron supports multiple languages, allowing you to contribute translations in your preferred language. Follow these steps to add support for a new language:

1. Install Dependency Package

Ensure you have the required package installed by running the following command:

pip install pybabel

2. Obtain the Translation Template

  1. Navigate to the app folder of the Neutron project.
  2. Locate the file named messages.pot, which contains the English text ready for translation.

3. Translate to Your Language

  1. Make a copy of messages.pot and translate its contents into your target language. Save this file with an appropriate name, e.g., messages_fr.po for French translations.

4. Initialize Language Configuration

Run the following commands from the terminal, replacing <your_translation_file> and <your_language_iso_code> accordingly:

cd app
pybabel init -i <your_translation_file> -d translations -l <your_language_iso_code>

For example:

pybabel init -i messages_fr.pot -d translations -l fr

5. Compile Translations

Once you've initialized the translation, compile the translated messages into a format that Neutron can use:

pybabel compile -d translations

6. Add your translation to the application

To incorporate a new language translation into Neutron, follow these steps to modify the source code:

  1. Update app/language.py:

    Open the language.py file in your application's codebase.

  2. Modify the LANGUAGES Dictionary:

    Locate the LANGUAGES dictionary within language.py and append the following entry:

    LANGUAGES = {
        'en': 'English',
        'vi': 'Vietnamese',
        '<your_language_iso_code>': '<your_language_name>'
    }

    Replace <your_language_iso_code> with the ISO code (e.g., 'fr' for French) and <your_language_name> with the corresponding language name (e.g., 'French').

7. Update Translations

If you make changes to your translations or if the English source messages are updated, use the following command to update your translations:

pybabel update -i <your_translation_file> -d translations

Ensure to replace <your_translation_file> with the updated source file if it has changed.

8. Add Your Language

To share your translation with the Neutron community, consider submitting your translated file to the project maintainers.