Internationalization and Localization

This section outlines the approach GitLab takes to support multiple languages and locales.

Overview

GitLab utilizes the gettext library for internationalization (i18n) and localization (l10n). This approach allows for the translation of user interface elements, error messages, and other text into different languages.

Workflow

  1. Identification: Developers identify text that needs to be translated within the GitLab codebase.
  2. Extraction: The gettext library extracts the identifiable text strings from the codebase.
  3. Translation: Translators translate the extracted strings into target languages.
  4. Compilation: The translated strings are compiled into language-specific files.
  5. Integration: The compiled files are integrated into GitLab, enabling users to select their preferred language.

Implementation

1. Marking Strings for Translation:

Developers mark strings for translation using the _ function provided by the gettext library.

Example:

_(“This is a string to be translated”)
          

This function takes the string as input and returns it as a marked string.

2. Extracting Strings:

The gettext library provides a tool called xgettext that extracts strings marked for translation from the codebase.

Example:

xgettext -o messages.pot -L Ruby --from-code=UTF-8 app/models/user.rb
          

This command extracts strings from the app/models/user.rb file and outputs them into a messages.pot file. This file serves as a template for translators.

3. Translation:

The extracted strings in the messages.pot file are then translated into target languages. GitLab utilizes a platform called Weblate for managing translations doc/development/i18n.md.

4. Compilation:

Translated strings are compiled into language-specific files called *.po files. These files contain the translated strings paired with their original English counterparts.

5. Integration:

The compiled *.po files are integrated into GitLab. The user interface and other text elements dynamically adapt to the user’s selected language.

Localization

Localization involves adapting the GitLab application to different cultures and locales. This includes factors such as:

  • Date and Time Formats: GitLab displays dates and times according to the user’s locale.
  • Number Formatting: Numbers, including currency values, are formatted according to the user’s locale.
  • Text Direction: GitLab supports both left-to-right and right-to-left languages.

Configuration

Users can select their preferred language in their GitLab account settings. GitLab automatically adjusts the interface based on the user’s selection.

Contributing to Translations

The GitLab community is encouraged to contribute to the translation process. Instructions for contributing can be found in the documentation doc/development/i18n.md.