Skip to content

Commit 023ea9a

Browse files
committed
fix: improve handling of dotted keys in getValueAtPath function
1 parent ea48d53 commit 023ea9a

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

scripts/find-missing-translations.js

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,44 @@ function findKeys(obj, parentKey = "") {
9292

9393
// Get value at a dotted path in an object
9494
function getValueAtPath(obj, path) {
95-
const parts = path.split(".")
95+
// Handle the case where keys might contain dots (like "glm-4.5")
96+
// We need to be smarter about splitting the path
9697
let current = obj
98+
let remainingPath = path
99+
100+
while (remainingPath && current && typeof current === "object") {
101+
let found = false
102+
103+
// Try to find the longest matching key first
104+
for (const key of Object.keys(current)) {
105+
if (remainingPath === key) {
106+
// Exact match - we're done
107+
return current[key]
108+
} else if (remainingPath.startsWith(key + ".")) {
109+
// Key matches the start of remaining path
110+
current = current[key]
111+
remainingPath = remainingPath.slice(key.length + 1)
112+
found = true
113+
break
114+
}
115+
}
97116

98-
for (const part of parts) {
99-
if (current === undefined || current === null) {
100-
return undefined
117+
if (!found) {
118+
// No matching key found, try the old method as fallback
119+
const dotIndex = remainingPath.indexOf(".")
120+
if (dotIndex === -1) {
121+
// No more dots, this should be the final key
122+
return current[remainingPath]
123+
} else {
124+
const nextKey = remainingPath.slice(0, dotIndex)
125+
if (current[nextKey] !== undefined) {
126+
current = current[nextKey]
127+
remainingPath = remainingPath.slice(dotIndex + 1)
128+
} else {
129+
return undefined
130+
}
131+
}
101132
}
102-
current = current[part]
103133
}
104134

105135
return current

0 commit comments

Comments
 (0)