This document shows how translations are managed in ERPNext and how to add a new language or update translations of an existing language.

1. Source

Translatable text exists in various sources:

  1. Javascript Code Files (both framework and application)

  2. Python Code Files

  3. HTML templates

  4. Workspace definitions

  5. DocTypes (names, labels and select options)

  6. and many more ...

Strings in Code Files

Strings in code files are annotated using the translation method

  1. In Python this is frappe._, for example:

frappe._("String {0} must be translated").format(txt)

  1. In Javascript it is the __ method. Example:

__("String {0} must be translated", [txt])

2. How Translations Are Picked up During Execution

Whenever a translation is called via the _ method, the entire translation dictionaries from all apps are built and stored in memcache.

Based on the user preferences or request preferences, the appropriate translations are loaded at the time of request on the server side. Or if metadata (DocType) is queried, then the appropriate translations are appended when the DocType data is requested.

The underscore _ method will replace the strings based on the available translations loaded at the time.

3. Adding New Translations

  1. To find untranslated strings, run bench get-untranslated [lang] [path]

  2. Add the translated strings in another file in the same order

  3. run bench update-translations [lang] [path of untranslated strings] [path of translated strings]

4. Improving Translations:

For updating translations, please go to the to the translation portal.

If you want to do it directly via code:

To improve an existing translation, just edit the master translation files in the translations of each app

Please contribute your translations back to ERPNext by sending us a Pull Request.

5. Bootstrapping a New Language

If you want to add a new language it is similar to adding new translations. You need to first export all the translations strings in one file, get them translated via Google Translate Tool or Bing Translate Tool and then import the translations into individual apps.

Step 1: Export to a file

$ bench get-untranslated [lang] [path]

Step 2: Translate

Create another file with updated translations (in the same order as the source file). For this you can use the Google Translator Toolkit or Bing Translator.

Step 3: Import your translations

$ bench update-translations [lang] [source path] [translated path]

Step 4: Update languages.txt

Add your language in apps/languages.txt and also frappe/data/languages.txt (fore new bench installs)

Step 5: Commit each app and push

A new file will be added to the translations folder in each app. You need to add that file and push to your repo. Then send us a pull-request.

On this page