patch menu build to use loaded language
This commit is contained in:
parent
24a350295c
commit
e7654b83b5
1 changed files with 9 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||||
|
|
||||||
import { $, h } from '../../moto/webui.js';
|
import { $, h } from '../../moto/webui.js';
|
||||||
|
import { api } from './api.js';
|
||||||
|
|
||||||
const { div, span, label, input, button, i, hr } = h;
|
const { div, span, label, input, button, i, hr } = h;
|
||||||
|
|
||||||
|
|
@ -12,6 +13,10 @@ function on(actions, id) {
|
||||||
return actions && typeof actions[id] === 'function' ? { onclick: actions[id] } : {};
|
return actions && typeof actions[id] === 'function' ? { onclick: actions[id] } : {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function tr(key, fallback) {
|
||||||
|
return api.language?.current?.[key] || fallback || key;
|
||||||
|
}
|
||||||
|
|
||||||
function menuItem(actions, { id, lk, xlk, text, title, iconClass, className, children }) {
|
function menuItem(actions, { id, lk, xlk, text, title, iconClass, className, children }) {
|
||||||
const attr = {
|
const attr = {
|
||||||
...(id ? { id } : {}),
|
...(id ? { id } : {}),
|
||||||
|
|
@ -23,8 +28,9 @@ function menuItem(actions, { id, lk, xlk, text, title, iconClass, className, chi
|
||||||
...(lk ? { lk } : {}),
|
...(lk ? { lk } : {}),
|
||||||
...(xlk ? { xlk } : {})
|
...(xlk ? { xlk } : {})
|
||||||
};
|
};
|
||||||
|
const resolved = lk ? tr(lk, text) : xlk ? tr(xlk, text) : text;
|
||||||
return div(attr, [
|
return div(attr, [
|
||||||
text !== undefined ? label({ ...lblAttr, _: text }) : undefined,
|
resolved !== undefined ? label({ ...lblAttr, _: resolved }) : undefined,
|
||||||
iconClass ? span([icon(iconClass)]) : undefined,
|
iconClass ? span([icon(iconClass)]) : undefined,
|
||||||
children
|
children
|
||||||
].filter(v => v !== undefined));
|
].filter(v => v !== undefined));
|
||||||
|
|
@ -37,8 +43,9 @@ function dropMenu(actions, side, items) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function topMenu(actions, { text, lk, iconClass, side = 'left', right = false, items }) {
|
function topMenu(actions, { text, lk, iconClass, side = 'left', right = false, items }) {
|
||||||
|
const resolved = lk ? tr(lk, text) : text;
|
||||||
return span({ class: right ? 'menu-right' : undefined }, [
|
return span({ class: right ? 'menu-right' : undefined }, [
|
||||||
text !== undefined ? label({ ...(lk ? { lk } : {}), _: text }) : undefined,
|
resolved !== undefined ? label({ ...(lk ? { lk } : {}), _: resolved }) : undefined,
|
||||||
iconClass ? icon(iconClass) : undefined,
|
iconClass ? icon(iconClass) : undefined,
|
||||||
dropMenu(actions, side, items)
|
dropMenu(actions, side, items)
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue