Switch regions from Setup > Region and show Chinese menu labels under zh_CN
This commit is contained in:
1 parent
56c8344fd2
commit
5f6c803b21
12 files changed
+408
-18
No files matched your search
@@ -37,6 +37,7 @@ Item {
|
||||
|
||||
function refresh() {
|
||||
defaultMenuFile.reload()
|
||||
localeMenuFile.reload()
|
||||
userMenuFile.reload()
|
||||
return "ok"
|
||||
}
|
||||
@@ -49,7 +50,9 @@ Item {
|
||||
// path doesn't have to shell out to bash + jq on every open.
|
||||
property string defaultMenuPath: omarchyPath + "/default/omarchy/omarchy-menu.jsonc"
|
||||
property string userMenuPath: Quickshell.env("HOME") + "/.config/omarchy/extensions/omarchy-menu.jsonc"
|
||||
property string localeMenuPath: (Quickshell.env("LANG") || "").startsWith("zh_CN") ? omarchyPath + "/default/omarchy/omarchy-menu.zh-cn.jsonc" : ""
|
||||
property var defaultMenuItems: []
|
||||
property var localeMenuItems: []
|
||||
property var userMenuItems: []
|
||||
property bool opened: false
|
||||
property string mode: "menu"
|
||||
@@ -247,7 +250,7 @@ Item {
|
||||
// on a per-key basis (so the user can tweak label/icon/action without
|
||||
// re-declaring the whole row).
|
||||
function rebuildItemsFromSources() {
|
||||
var mergedMenu = MenuModel.mergeMenuSources(root.defaultMenuItems, root.userMenuItems)
|
||||
var mergedMenu = MenuModel.mergeMenuSources(root.defaultMenuItems, root.localeMenuItems.concat(root.userMenuItems))
|
||||
root.providerRevision += 1
|
||||
root.providersLoaded = ({})
|
||||
root.providerQueue = []
|
||||
@@ -974,6 +977,16 @@ Item {
|
||||
onFileChanged: reload()
|
||||
}
|
||||
|
||||
FileView {
|
||||
id: localeMenuFile
|
||||
path: root.localeMenuPath
|
||||
watchChanges: true
|
||||
printErrors: false
|
||||
onLoaded: { root.localeMenuItems = root.parseMenuJsonc(text()); root.rebuildItemsFromSources() }
|
||||
onLoadFailed: { root.localeMenuItems = []; root.rebuildItemsFromSources() }
|
||||
onFileChanged: reload()
|
||||
}
|
||||
|
||||
FileView {
|
||||
id: userMenuFile
|
||||
path: root.userMenuPath
|
||||
|
||||
@@ -58,7 +58,9 @@ function parseMenuJsonc(raw) {
|
||||
for (var id in source) {
|
||||
var entry = source[id]
|
||||
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue
|
||||
out.push(normalizeItem(id, entry))
|
||||
var item = normalizeItem(id, entry)
|
||||
item.declared = Object.keys(entry)
|
||||
out.push(item)
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -74,11 +76,24 @@ function mergeMenuSources(defaultItems, userItems) {
|
||||
var entry = src[i]
|
||||
if (!entry || !entry.id) continue
|
||||
if (!nextItems[entry.id]) nextOrder.push(entry.id)
|
||||
var prior = nextItems[entry.id] || {}
|
||||
var prior = nextItems[entry.id]
|
||||
var merged = {}
|
||||
for (var k in prior) merged[k] = prior[k]
|
||||
for (var k2 in entry) merged[k2] = entry[k2]
|
||||
// An override replaces only the fields its file declared.
|
||||
if (prior && entry.declared) {
|
||||
for (var k in prior) merged[k] = prior[k]
|
||||
for (var d = 0; d < entry.declared.length; d++) {
|
||||
var key = entry.declared[d]
|
||||
if (key in entry) merged[key] = entry[key]
|
||||
}
|
||||
if (entry.declared.indexOf("action") >= 0 || entry.declared.indexOf("target") >= 0)
|
||||
merged.kind = merged.action ? "action" : (merged.target ? "link" : "menu")
|
||||
} else {
|
||||
prior = prior || {}
|
||||
for (var k1 in prior) merged[k1] = prior[k1]
|
||||
for (var k2 in entry) merged[k2] = entry[k2]
|
||||
}
|
||||
merged.id = entry.id
|
||||
delete merged.declared
|
||||
nextItems[entry.id] = merged
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user