From 78f4b34954f02d08c40d3193d7e981839cb6980f Mon Sep 17 00:00:00 2001 From: Ali <010109ali@gmail.com> Date: Thu, 11 Jun 2026 11:46:07 +0000 Subject: [PATCH] feat(listview): centralize subject translator across translated doctypes Replace per-doctype scorecard list scripts with one shared translate_listview_subjects.js covering Activity Type, Market Segment, Role, Role Profile, UOM, Territory, Price List, and the supplier scorecards. Add missing az/ru translations for Communication and Azerbaijan. Co-Authored-By: Claude Opus 4.8 (1M context) --- az_locale/hooks.py | 13 +++++-- .../locale/translations_az/erpnext/extras.po | 12 +++++++ .../locale/translations_ru/erpnext/extras.po | 12 +++++++ .../js/supplier_scorecard_standing_list.js | 20 ----------- .../js/supplier_scorecard_variable_list.js | 18 ---------- .../public/js/translate_listview_subjects.js | 34 +++++++++++++++++++ 6 files changed, 69 insertions(+), 40 deletions(-) delete mode 100644 az_locale/public/js/supplier_scorecard_standing_list.js delete mode 100644 az_locale/public/js/supplier_scorecard_variable_list.js create mode 100644 az_locale/public/js/translate_listview_subjects.js diff --git a/az_locale/hooks.py b/az_locale/hooks.py index 97154d3..01495b6 100644 --- a/az_locale/hooks.py +++ b/az_locale/hooks.py @@ -52,9 +52,18 @@ after_migrate = "az_locale.install.after_install" # include js in doctype views # doctype_js = {"doctype" : "public/js/doctype.js"} +# All these doctypes share one centralized list-view subject translator. +_listview_subject_js = "public/js/translate_listview_subjects.js" doctype_list_js = { - "Supplier Scorecard Standing": "public/js/supplier_scorecard_standing_list.js", - "Supplier Scorecard Variable": "public/js/supplier_scorecard_variable_list.js", + "Supplier Scorecard Standing": _listview_subject_js, + "Supplier Scorecard Variable": _listview_subject_js, + "Activity Type": _listview_subject_js, + "Market Segment": _listview_subject_js, + "Role": _listview_subject_js, + "Role Profile": _listview_subject_js, + "UOM": _listview_subject_js, + "Territory": _listview_subject_js, + "Price List": _listview_subject_js, } # doctype_tree_js = {"doctype" : "public/js/doctype_tree.js"} # doctype_calendar_js = {"doctype" : "public/js/doctype_calendar.js"} diff --git a/az_locale/locale/translations_az/erpnext/extras.po b/az_locale/locale/translations_az/erpnext/extras.po index 36eca1f..294b211 100644 --- a/az_locale/locale/translations_az/erpnext/extras.po +++ b/az_locale/locale/translations_az/erpnext/extras.po @@ -196,3 +196,15 @@ msgstr "Ümumi Çatdırılmalar" msgid "Total Working Days" msgstr "Ümumi İş Günləri" + +#. Activity Type fixture value missing from upstream erpnext .po (the other +#. defaults — Planning/Research/Proposal Writing/Execution — are already +#. translated upstream). Activity Type already ships with translated_doctype=1. +# === Activity Type === +msgid "Communication" +msgstr "Kommunikasiya" + +#. Territory record (also the country name) — missing from upstream erpnext .po. +# === Territory === +msgid "Azerbaijan" +msgstr "Azərbaycan" diff --git a/az_locale/locale/translations_ru/erpnext/extras.po b/az_locale/locale/translations_ru/erpnext/extras.po index c283531..bfcaa8a 100644 --- a/az_locale/locale/translations_ru/erpnext/extras.po +++ b/az_locale/locale/translations_ru/erpnext/extras.po @@ -196,3 +196,15 @@ msgstr "Всего отгрузок" msgid "Total Working Days" msgstr "Всего рабочих дней" + +#. Activity Type fixture value missing from upstream erpnext .po (the other +#. defaults — Planning/Research/Proposal Writing/Execution — are already +#. translated upstream). Activity Type already ships with translated_doctype=1. +# === Activity Type === +msgid "Communication" +msgstr "Коммуникация" + +#. Territory record (also the country name) — missing from upstream erpnext .po. +# === Territory === +msgid "Azerbaijan" +msgstr "Азербайджан" diff --git a/az_locale/public/js/supplier_scorecard_standing_list.js b/az_locale/public/js/supplier_scorecard_standing_list.js deleted file mode 100644 index 4952bff..0000000 --- a/az_locale/public/js/supplier_scorecard_standing_list.js +++ /dev/null @@ -1,20 +0,0 @@ -// The "Translate Link Fields" (translated_doctype) flag makes Link references to -// Supplier Scorecard Standing translate, but the doctype's OWN list view shows the -// document `name` as the subject column, and list_view.js only auto-translates -// columns whose df.options is a translated doctype (i.e. Link columns) — not the -// subject. get_subject_text() does apply a registered formatter for the subject -// field though (the subject field here is `name`, since the doctype has no -// title_field), so we translate it ourselves. -frappe.listview_settings["Supplier Scorecard Standing"] = Object.assign( - frappe.listview_settings["Supplier Scorecard Standing"] || {}, - { - formatters: Object.assign( - (frappe.listview_settings["Supplier Scorecard Standing"] || {}).formatters || {}, - { - name(value) { - return __(value); - }, - } - ), - } -); diff --git a/az_locale/public/js/supplier_scorecard_variable_list.js b/az_locale/public/js/supplier_scorecard_variable_list.js deleted file mode 100644 index c21f345..0000000 --- a/az_locale/public/js/supplier_scorecard_variable_list.js +++ /dev/null @@ -1,18 +0,0 @@ -// translated_doctype makes Link references to Supplier Scorecard Variable translate, -// but the doctype's OWN list view shows the document `name` as the subject column, -// which list_view.js does not auto-translate. get_subject_text() applies a registered -// formatter for the subject field (here `name`, since the doctype has no title_field), -// so we translate it ourselves. See supplier_scorecard_standing_list.js for details. -frappe.listview_settings["Supplier Scorecard Variable"] = Object.assign( - frappe.listview_settings["Supplier Scorecard Variable"] || {}, - { - formatters: Object.assign( - (frappe.listview_settings["Supplier Scorecard Variable"] || {}).formatters || {}, - { - name(value) { - return __(value); - }, - } - ), - } -); diff --git a/az_locale/public/js/translate_listview_subjects.js b/az_locale/public/js/translate_listview_subjects.js new file mode 100644 index 0000000..7a0b006 --- /dev/null +++ b/az_locale/public/js/translate_listview_subjects.js @@ -0,0 +1,34 @@ +// Centralized list-view subject translator. +// +// For doctypes whose record names are translatable data (translated_doctype=1), +// Link references already translate, but the doctype's OWN list view shows the +// subject/title column untranslated: list_view.js only auto-translates columns +// whose df.options is a translated doctype (i.e. Link columns), not the subject. +// get_subject_text() does apply a formatter registered for the subject field, so +// we register one here that runs the value through __(). +// +// Map: doctype -> subject fieldname. That is the doctype's title_field if it has +// one, otherwise "name" (the list subject column falls back to name — see +// list_view.js setup_columns()). +const AZ_LOCALE_SUBJECT_FIELDS = { + "Supplier Scorecard Standing": "name", + "Supplier Scorecard Variable": "name", + "Activity Type": "name", + "Market Segment": "name", + "Role": "name", + "Role Profile": "role_profile", + UOM: "name", + Territory: "name", + "Price List": "name", +}; + +for (const [doctype, field] of Object.entries(AZ_LOCALE_SUBJECT_FIELDS)) { + const existing = frappe.listview_settings[doctype] || {}; + frappe.listview_settings[doctype] = Object.assign(existing, { + formatters: Object.assign(existing.formatters || {}, { + [field](value) { + return __(value); + }, + }), + }); +}