From dee31d739b25c598e07aca7423e9f25c362c87d4 Mon Sep 17 00:00:00 2001 From: Ali <010109ali@gmail.com> Date: Mon, 13 Jul 2026 10:54:44 +0000 Subject: [PATCH] feat(i18n): English source-string overrides + clear translation cache Add locale/translations_en/{frappe,erpnext}/en.po so we can rewrite English source strings we are not happy with. English is not special-cased anywhere in Frappe's runtime, so setup_locale() picks these up with no changes: it derives the locale from the translations_ folder name, copies each en.po into the target app and compiles it to sites/assets/locale/en/LC_MESSAGES/.mo. Both files ship empty (header only) for now. Also clear the merged-translation cache once all .mo files are written. bench migrate clears that cache *before* running after_migrate hooks, and it refills during migration (patches and syncs call _() under lang "en"), so the .mo files we write afterwards stayed invisible until someone ran `bench clear-cache` by hand. This affected az/ru too. Co-Authored-By: Claude Opus 4.8 (1M context) --- az_locale/locale/setup_locale.py | 19 ++++++++++++++ .../locale/translations_en/erpnext/en.po | 26 +++++++++++++++++++ az_locale/locale/translations_en/frappe/en.po | 26 +++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 az_locale/locale/translations_en/erpnext/en.po create mode 100644 az_locale/locale/translations_en/frappe/en.po diff --git a/az_locale/locale/setup_locale.py b/az_locale/locale/setup_locale.py index 398542a..4eb2d0b 100644 --- a/az_locale/locale/setup_locale.py +++ b/az_locale/locale/setup_locale.py @@ -59,12 +59,31 @@ def setup_locale(): # would otherwise keep serving a stale .mo. _compile_mo(app_name, lang) + _clear_translation_cache() + print( f"[az_locale] Locale setup complete: {copied} file(s) copied, " f"{merged} extras merged, {skipped} skipped" ) +def _clear_translation_cache(): + """Drop the cached merged-translation dict so the fresh .mo files are picked up. + + `bench migrate` clears this cache *before* running after_migrate hooks, and the + cache refills during migration (patches and syncs call _() under lang "en"). + Since we write the .mo files afterwards, they would stay invisible until someone + ran `bench clear-cache` by hand. + """ + try: + import frappe.translate + + frappe.translate.clear_cache() + print("[az_locale] Cleared translation cache") + except Exception as e: + print(f"[az_locale] Warning: could not clear translation cache ({e})") + + def _compile_mo(app_name, lang): """Compile the app's .po into the runtime .mo under sites/assets/locale/. diff --git a/az_locale/locale/translations_en/erpnext/en.po b/az_locale/locale/translations_en/erpnext/en.po new file mode 100644 index 0000000..c4fd084 --- /dev/null +++ b/az_locale/locale/translations_en/erpnext/en.po @@ -0,0 +1,26 @@ +# +# English overrides for the "erpnext" app. +# +# This file is NOT a translation — it rewrites English source strings we are not +# happy with. It is copied to apps/erpnext/erpnext/locale/en.po by setup_locale() +# and compiled into sites/assets/locale/en/LC_MESSAGES/erpnext.mo on migrate. +# +# Rules: +# - msgid must match the source string byte for byte (case, punctuation, +# %s placeholders). Look them up in apps/erpnext/erpnext/locale/main.pot. +# - An empty msgstr means "no override" — the original string is used. +# - An override applies to that string everywhere. To narrow it down, add a +# msgctxt line above the msgid. +# - Keep this file small: the whole English dict ships in every session's boot. +# +# Example: +# msgid "Customer" +# msgstr "Client" +# +msgid "" +msgstr "" +"Project-Id-Version: erpnext\n" +"Language: en\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" diff --git a/az_locale/locale/translations_en/frappe/en.po b/az_locale/locale/translations_en/frappe/en.po new file mode 100644 index 0000000..75238b2 --- /dev/null +++ b/az_locale/locale/translations_en/frappe/en.po @@ -0,0 +1,26 @@ +# +# English overrides for the "frappe" app. +# +# This file is NOT a translation — it rewrites English source strings we are not +# happy with. It is copied to apps/frappe/frappe/locale/en.po by setup_locale() +# and compiled into sites/assets/locale/en/LC_MESSAGES/frappe.mo on migrate. +# +# Rules: +# - msgid must match the source string byte for byte (case, punctuation, +# %s placeholders). Look them up in apps/frappe/frappe/locale/main.pot. +# - An empty msgstr means "no override" — the original string is used. +# - An override applies to that string everywhere. To narrow it down, add a +# msgctxt line above the msgid. +# - Keep this file small: the whole English dict ships in every session's boot. +# +# Example: +# msgid "Submit" +# msgstr "Post" +# +msgid "" +msgstr "" +"Project-Id-Version: frappe\n" +"Language: en\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n"