MCPcopy Index your code
hub / github.com/bytebase/bytebase / addMissingKeysFromSource

Function addMissingKeysFromSource

frontend/i18n.ts:144–177  ·  view source on GitHub ↗
(
  source: JsonObject,
  target: JsonObject,
  lang: string
)

Source from the content-addressed store, hash-verified

142}
143
144async function addMissingKeysFromSource(
145 source: JsonObject,
146 target: JsonObject,
147 lang: string
148): Promise<JsonObject> {
149 const merged: JsonObject = {};
150 const keys = new Set([...Object.keys(source), ...Object.keys(target)]);
151
152 for (const key of keys) {
153 if (key in source && !(key in target)) {
154 // Key exists in source but not in target
155 merged[key] = await translateJsonValue(source[key], lang);
156 } else if (
157 key in source &&
158 key in target &&
159 typeof source[key] === "object" &&
160 !Array.isArray(source[key]) &&
161 typeof target[key] === "object" &&
162 !Array.isArray(target[key])
163 ) {
164 // Both have the key and its value is an object, merge recursively
165 merged[key] = await addMissingKeysFromSource(
166 source[key] as JsonObject,
167 target[key] as JsonObject,
168 lang
169 );
170 } else {
171 // Key exists in target or both, prefer target's value
172 merged[key] = target[key];
173 }
174 }
175
176 return merged;
177}
178
179// Main function to load the source file and update each target file
180async function updateLocalizationFiles() {

Callers 1

updateLocalizationFilesFunction · 0.85

Calls 2

translateJsonValueFunction · 0.85
keysMethod · 0.80

Tested by

no test coverage detected