How to Translate Texts, Labels, and Messages in Frappe ( On custom apps ) )

Steps required to translate texts, labels and messages on Frappe.

 · 1 min read

The history of Arabic Language | Verbling


Translating your Frappe app to support multiple languages helps you reach more users and enhances usability. This guide walks you through how to add translations — using Arabic (ar) as an example. If you’re working with another language (e.g., French), just replace ar with the appropriate ISO language code.


One-Time Setup: Translation File Structure


In your custom app, create a folder named translations and place your CSV file like this:


your_app/

└── your_app/

   └── translations/

       └── ar.csv



Sample ar.csv


Source Text,Translated Text

How are you,كيف حالك

Submit,إرسال

"This, is a test","هذا، هو اختبار"


Note: If your text contains commas, wrap the entry in double quotes ("...").



In your Python files:

from frappe import _


Wrap translatable strings using the underscore function _():

message = _("How are you")


Frappe will automatically translate this using the appropriate language CSV file (e.g., ar.csv) based on the user’s language preference.


After modifying the ar.csv file:

bench --site yoursite.local clear-cache



If you’re responding to an external request (like an API call) where no user is logged in, set the language manually:

frappe.local.lang = "ar"

print(_("How are you"))  # Output: كيف حالك



Note:

  1. Always ensure your text matches exactly between _() and your CSV entries.



No comments yet.

Add a comment
Ctrl+Enter to add comment