icons: resolve localized menu labels via img src
Menu titles in the app switcher dropdown and sidebar header are translated (e.g. Azerbaijani), so looking up THEME_ICONS by textContent missed everything. resolveEnglishKey() now extracts the untranslated icon name from the <img src> URL, falls back to scanning frappe.boot.desktop_icons for a matching __(label), then the text. Also adds a "taxes az" alias to THEME_ICONS.chrome so our new Taxes Az desktop icon renders the tax document SVG instead of the alphabet fallback. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
96099513a1
commit
6c59231f43
|
|
@ -103,6 +103,7 @@
|
||||||
payments: { paths: '<rect x="1" y="4" width="22" height="16" rx="2"/><line x1="1" y1="10" x2="23" y2="10"/><line x1="5" y1="15" x2="9" y2="15"/><line x1="13" y1="15" x2="15" y2="15"/>' },
|
payments: { paths: '<rect x="1" y="4" width="22" height="16" rx="2"/><line x1="1" y1="10" x2="23" y2="10"/><line x1="5" y1="15" x2="9" y2="15"/><line x1="13" y1="15" x2="15" y2="15"/>' },
|
||||||
"financial reports": { paths: '<path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="8" y1="13" x2="16" y2="13"/><line x1="8" y1="17" x2="16" y2="17"/><line x1="8" y1="9" x2="10" y2="9"/>' },
|
"financial reports": { paths: '<path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="8" y1="13" x2="16" y2="13"/><line x1="8" y1="17" x2="16" y2="17"/><line x1="8" y1="9" x2="10" y2="9"/>' },
|
||||||
taxes: { paths: '<path d="M4 2h16a2 2 0 012 2v16a2 2 0 01-2 2H4a2 2 0 01-2-2V4a2 2 0 012-2z"/><line x1="9" y1="8" x2="15" y2="8"/><line x1="9" y1="12" x2="15" y2="12"/><line x1="9" y1="16" x2="13" y2="16"/><line x1="6" y1="8" x2="6" y2="8.01" stroke-width="2"/><line x1="6" y1="12" x2="6" y2="12.01" stroke-width="2"/><line x1="6" y1="16" x2="6" y2="16.01" stroke-width="2"/>' },
|
taxes: { paths: '<path d="M4 2h16a2 2 0 012 2v16a2 2 0 01-2 2H4a2 2 0 01-2-2V4a2 2 0 012-2z"/><line x1="9" y1="8" x2="15" y2="8"/><line x1="9" y1="12" x2="15" y2="12"/><line x1="9" y1="16" x2="13" y2="16"/><line x1="6" y1="8" x2="6" y2="8.01" stroke-width="2"/><line x1="6" y1="12" x2="6" y2="12.01" stroke-width="2"/><line x1="6" y1="16" x2="6" y2="16.01" stroke-width="2"/>' },
|
||||||
|
"taxes az": { paths: '<path d="M4 2h16a2 2 0 012 2v16a2 2 0 01-2 2H4a2 2 0 01-2-2V4a2 2 0 012-2z"/><line x1="9" y1="8" x2="15" y2="8"/><line x1="9" y1="12" x2="15" y2="12"/><line x1="9" y1="16" x2="13" y2="16"/><line x1="6" y1="8" x2="6" y2="8.01" stroke-width="2"/><line x1="6" y1="12" x2="6" y2="12.01" stroke-width="2"/><line x1="6" y1="16" x2="6" y2="16.01" stroke-width="2"/>' },
|
||||||
banking: { paths: '<path d="M3 21h18"/><path d="M3 10h18"/><path d="M12 3l9 7H3l9-7z"/><line x1="6" y1="10" x2="6" y2="21"/><line x1="10" y1="10" x2="10" y2="21"/><line x1="14" y1="10" x2="14" y2="21"/><line x1="18" y1="10" x2="18" y2="21"/>' },
|
banking: { paths: '<path d="M3 21h18"/><path d="M3 10h18"/><path d="M12 3l9 7H3l9-7z"/><line x1="6" y1="10" x2="6" y2="21"/><line x1="10" y1="10" x2="10" y2="21"/><line x1="14" y1="10" x2="14" y2="21"/><line x1="18" y1="10" x2="18" y2="21"/>' },
|
||||||
budget: { paths: '<line x1="12" y1="1" x2="12" y2="23"/><path d="M17 5H9.5a3.5 3.5 0 000 7h5a3.5 3.5 0 010 7H6"/>' },
|
budget: { paths: '<line x1="12" y1="1" x2="12" y2="23"/><path d="M17 5H9.5a3.5 3.5 0 000 7h5a3.5 3.5 0 010 7H6"/>' },
|
||||||
"share management": { paths: '<polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/>' },
|
"share management": { paths: '<polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/>' },
|
||||||
|
|
@ -302,6 +303,30 @@
|
||||||
the current theme's SVG icons (same as desktop).
|
the current theme's SVG icons (same as desktop).
|
||||||
================================================================== */
|
================================================================== */
|
||||||
|
|
||||||
|
/* Menu titles are localized (e.g. Azerbaijani "Mühasibat uçotu"), so the
|
||||||
|
lookup key is taken from the untranslated img src filename first, then
|
||||||
|
from a reverse-lookup over frappe.boot.desktop_icons by __(label), and
|
||||||
|
only last from the displayed text as a best-effort fallback. */
|
||||||
|
function resolveEnglishKey(item) {
|
||||||
|
var img = item.querySelector("img.logo[src]");
|
||||||
|
if (img) {
|
||||||
|
var m = img.getAttribute("src").match(/\/([^\/]+)\.svg(\?|$)/);
|
||||||
|
if (m) return m[1].replace(/_/g, " ").toLowerCase();
|
||||||
|
}
|
||||||
|
var titleEl = item.querySelector(".menu-item-title, .header-title");
|
||||||
|
if (!titleEl) return null;
|
||||||
|
var titleText = titleEl.textContent.trim();
|
||||||
|
if (window.frappe && frappe.boot && Array.isArray(frappe.boot.desktop_icons) && typeof __ === "function") {
|
||||||
|
for (var i = 0; i < frappe.boot.desktop_icons.length; i++) {
|
||||||
|
var dIcon = frappe.boot.desktop_icons[i];
|
||||||
|
if (dIcon && dIcon.label && __(dIcon.label) === titleText) {
|
||||||
|
return dIcon.label.toLowerCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return titleText.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
function processContextMenuIcons() {
|
function processContextMenuIcons() {
|
||||||
document.querySelectorAll(".frappe-menu .dropdown-menu-item").forEach(function (item) {
|
document.querySelectorAll(".frappe-menu .dropdown-menu-item").forEach(function (item) {
|
||||||
var iconDiv = item.querySelector(".menu-item-icon");
|
var iconDiv = item.querySelector(".menu-item-icon");
|
||||||
|
|
@ -310,11 +335,7 @@
|
||||||
// Skip chevron icons (the second .menu-item-icon with margin-left:auto)
|
// Skip chevron icons (the second .menu-item-icon with margin-left:auto)
|
||||||
if (iconDiv.style.marginLeft === "auto") return;
|
if (iconDiv.style.marginLeft === "auto") return;
|
||||||
|
|
||||||
var titleEl = item.querySelector(".menu-item-title");
|
var key = resolveEnglishKey(item);
|
||||||
if (!titleEl) return;
|
|
||||||
|
|
||||||
var key = titleEl.textContent.trim().toLowerCase();
|
|
||||||
// Only replace if there's a real icon in THEME_ICONS (skip unknown items)
|
|
||||||
if (!hasIconDef(key)) return;
|
if (!hasIconDef(key)) return;
|
||||||
|
|
||||||
iconDiv.innerHTML = "";
|
iconDiv.innerHTML = "";
|
||||||
|
|
@ -333,10 +354,7 @@
|
||||||
var logo = header.querySelector(".header-logo");
|
var logo = header.querySelector(".header-logo");
|
||||||
if (!logo || logo.querySelector(".jey-icon")) return;
|
if (!logo || logo.querySelector(".jey-icon")) return;
|
||||||
|
|
||||||
var titleEl = header.querySelector(".header-title");
|
var key = resolveEnglishKey(header);
|
||||||
if (!titleEl) return;
|
|
||||||
|
|
||||||
var key = titleEl.textContent.trim().toLowerCase();
|
|
||||||
if (!hasIconDef(key)) return;
|
if (!hasIconDef(key)) return;
|
||||||
|
|
||||||
logo.innerHTML = "";
|
logo.innerHTML = "";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue