From 023ea9adaebd22825e435c328ba181857f9ae2c7 Mon Sep 17 00:00:00 2001 From: Hannes Rudolph Date: Thu, 18 Sep 2025 18:24:29 -0600 Subject: [PATCH] fix: improve handling of dotted keys in getValueAtPath function --- scripts/find-missing-translations.js | 40 ++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/scripts/find-missing-translations.js b/scripts/find-missing-translations.js index 9277d935ba..fd00025c6c 100755 --- a/scripts/find-missing-translations.js +++ b/scripts/find-missing-translations.js @@ -92,14 +92,44 @@ function findKeys(obj, parentKey = "") { // Get value at a dotted path in an object function getValueAtPath(obj, path) { - const parts = path.split(".") + // Handle the case where keys might contain dots (like "glm-4.5") + // We need to be smarter about splitting the path let current = obj + let remainingPath = path - for (const part of parts) { - if (current === undefined || current === null) { - return undefined + while (remainingPath && current && typeof current === "object") { + let found = false + + // Try to find the longest matching key first + for (const key of Object.keys(current)) { + if (remainingPath === key) { + // Exact match - we're done + return current[key] + } else if (remainingPath.startsWith(key + ".")) { + // Key matches the start of remaining path + current = current[key] + remainingPath = remainingPath.slice(key.length + 1) + found = true + break + } + } + + if (!found) { + // No matching key found, try the old method as fallback + const dotIndex = remainingPath.indexOf(".") + if (dotIndex === -1) { + // No more dots, this should be the final key + return current[remainingPath] + } else { + const nextKey = remainingPath.slice(0, dotIndex) + if (current[nextKey] !== undefined) { + current = current[nextKey] + remainingPath = remainingPath.slice(dotIndex + 1) + } else { + return undefined + } + } } - current = current[part] } return current