diff --git a/custom_subtabs/public/js/custom_subtabs.js b/custom_subtabs/public/js/custom_subtabs.js index 1cbe177..9516207 100644 --- a/custom_subtabs/public/js/custom_subtabs.js +++ b/custom_subtabs/public/js/custom_subtabs.js @@ -17,6 +17,13 @@ function setup_custom_subtabs(wrapper, currentDoctype) { return; } + // tab_hierarchy хранит СЫРЫЕ (английские) label'ы, а Frappe рисует вкладки + // через __(), т.е. в DOM текст уже переведён (AZ/RU). Поэтому сопоставлять + // вкладку из DOM с ключом иерархии нужно через перевод этого ключа. + // Внутренние структуры (childToParentMap, data-subtab-name) оставляем на + // английском — переводим только на границе сравнения с DOM. + const tr = (s) => (typeof __ === 'function' ? __(s) : s); + // Helper function to find tab link element function getTabLink(tabElement) { const $tab = $(tabElement); @@ -44,7 +51,11 @@ function setup_custom_subtabs(wrapper, currentDoctype) { tabs.each((index, tab) => { const tabLabel = $(tab).text().trim(); - if (subtabs[tabLabel]) { + // tabLabel — переведённый текст из DOM; ключ иерархии — английский. + // Находим английский ключ-родитель, чей перевод совпал с DOM. + const parentKey = Object.keys(subtabs).find((k) => tr(k) === tabLabel); + + if (parentKey) { const tabLink = getTabLink(tab); const tabContentId = tabLink.attr("aria-controls"); const tabContent = $(`#${tabContentId}`); @@ -71,11 +82,13 @@ function setup_custom_subtabs(wrapper, currentDoctype) { sectionContainer.prepend(subtabContainer); } - subtabs[tabLabel].forEach((subtab) => { - const subtabElement = tabs.filter((_, el) => $(el).text().trim() === subtab); + subtabs[parentKey].forEach((subtab) => { + // subtab — английский; в DOM ищем по его переводу. + const subtabElement = tabs.filter((_, el) => $(el).text().trim() === tr(subtab)); if (subtabElement.length) { const subtabClone = subtabElement.clone(true); subtabClone.addClass("sub-tab"); + // data-subtab-name держим английским — childToParentMap/ensureParentChainVisible на нём. subtabClone.attr("data-subtab-name", subtab); const clonedLink = getTabLink(subtabClone); clonedLink.removeAttr("href");