Skip to main content

Translations Library

Proposed change

Create a library to contain all the PM-Netbank translations.

Instead of having the translations for each app in the app's src, the translations will be centralized in a unique library. This way it will be possible to share translations between applications or libraries.

How it looks now

In each app or library, under src/services there's a folder named i18n which contains the translations for the app/library.

  • src/services
    • i18n
      • translations
        • en
        • no
        • translationKeys.ts

In the code, when we need to use one of the translations, we import translationKeys and use the key we need.

import { translationKeys } from '../../services/i18n';
...
<FormattedMessage id={translationKeys.myapp_mykey} />

Alternative

Create a library @pm-netbank/translations which will contain the translations for all the apps and libraries in PM-Netbank.

import { translationKeys } from '@pm-netbank/translations';
...
<FormattedMessage id={translationKeys.myapp_mykey} />

Motivation

There are some cases where it's necessary to share the exact same translation between different apps.

It would be possible to duplicate the keys, but that would lead to extra effort in the future in the case the translations change.

Also, there are some scenarios where the translations are shared across multiple applications. For example, the translation for the term "homepage" should be the same in every app.

Right now, it is necessary to duplicate the translation in every app. With this change, a translation could be reused everywhere and updated at the same time, if the value changes.

Proposed transition strategy

  1. The lokalise.sh script must be updated to download the translations to the new library

    • Maybe we should keep two versions of the script while the transition is going?
  2. In each one of the apps and libraries, the translations should be imported from the new library

  3. In each one of the apps and libraries, the old deprecated translation files should be deleted