Skip to main content

Internationalization

Pupilfirst LMS uses Rails Internationalization (I18n) API for internationalization and localization.

Adding a new language

Let's imagine that you're trying to add translations for a language with the ISO 639 code lang. These are the steps you'd have to take:

Create the language's YML file

Create a file at the location config/locales/lang.yml. Follow Rails-conventions for authoring a translation file. Also go through the section below on how we've organized the contents of the en.yml file.

Make translations accessible to front-end code

Load the new language's translations in front-end code by editing app/frontend/shared/i18n.js and adding:

// ...other language imports
import trLang from "../locales/lang.json";

const i18n = new I18n();

// ...other language stores
i18n.store(trLang);

This will make relevant language strings accessible to client-side code.

Making the new language available to users

Add lang to the comma-separated list in the environment variavble I18N_AVAILABLE_LOCALES. This will add lang to the list of languages available for selection via users' Profile Edit page.

Setting the new language as default

If you'd like to set the language you're adding as the default for your deployment of the LMS, set the I18N_DEFAULT_LOCALE environment variable to lang.

Organization of en.yml

KeyValue
components.COMPONENT.*Component-specific strings.
jobs.MODULE.CLASS.*Strings used by jobs.
layouts.PATHStrings used in layouts.
mailers.CLASS.ACTION.*Strings used in mailers.
models.MODEL.COLUMN.*Translation of database values to display values.
mutations.MUTATION.*Strings used by mutations.
presenters.MODULE.CLASS.*Presenter-specific strings.
queries.QUERY.*Strings used by resolvers and mutators.
services.MODULE.CLASS.*Strings used by services.
shared.*Shared strings.
CONTROLLER.ACTION.*Request-based responses.
MODULE.CLASS.*Strings used by library code.

YAML Sort

You should use the YAML Sort Visual Studio Code extension to validate and sort the contents of LANG.yml files.

Use the following configuration when using this extension:

{
"vscode-yaml-sort.quotingType": "\"",
"vscode-yaml-sort.useLeadingDashes": false
}

Third-party library translations

  • errors.messages.content_type_invalid and errors.messages.limit_out_of_range are custom error messages for the active_storage_validations gem.