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) <noreply@anthropic.com>
This commit is contained in:
Ali 2026-06-11 11:46:07 +00:00
parent 62b4fdbea5
commit 78f4b34954
6 changed files with 69 additions and 40 deletions

View File

@ -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"}

View File

@ -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"

View File

@ -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 "Азербайджан"

View File

@ -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);
},
}
),
}
);

View File

@ -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);
},
}
),
}
);

View File

@ -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);
},
}),
});
}