Skip to content

Instantly share code, notes, and snippets.

@walkermatt
Last active October 15, 2025 14:58
Show Gist options
  • Save walkermatt/b9fb5cb737117e11ef066c2c7e8eda7f to your computer and use it in GitHub Desktop.
Save walkermatt/b9fb5cb737117e11ef066c2c7e8eda7f to your computer and use it in GitHub Desktop.
Transform iShare language strings in JSON format to XML format
const lang = {
lang: {
oli: {
baseMapsTitle: "Base maps",
deviceLocation: {
showLocation: "Show your location",
},
fullScreen: {
tipLabel: "Toggle full-screen",
},
gazetteer: {
noResults: "No results found",
placeholder: "Search...",
queryTooShort: "Type ${minQueryLength} or more characters for results",
selectedOption:
"${selectedOption} ${index} of ${length} is highlighted",
resultsDescription: "Result count: ${length}. ${selectedOption}",
assistiveHint:
"When autocomplete results are available, use the up and down arrows to review and enter to select. Users of touch devices can explore by touch or with swipe gestures.",
},
layerSwitcher: {
hideButtonTitle: "Collapse legend",
showButtonTitle: "Show legend",
},
historyNavigation: {
backHtml: "⇐",
backTitle: "Navigate back",
forwardHtml: "⇒",
forwardTitle: "Navigate forward",
},
zoom: {
zoomInTipLabel: "Zoom in",
zoomOutTipLabel: "Zoom out",
},
apps: {
spotlight: {
baseMapsTitle: "Base layer",
gazetteer: {
placeholder: "Partial address or postcode...",
},
},
},
},
},
};
function toPathValues(obj) {
let pathVals = [];
let _keys = [];
function walk(o) {
for (let k in o) {
let v = o[k];
// console.log(k, v);
_keys.push(k);
if (v instanceof Object) {
// console.log('walking...', _keys, v);
walk(v);
_keys.pop();
} else {
// console.log('leaf', _keys, v);
pathVals.push({ path: _keys.join("."), value: v });
_keys.pop();
}
}
}
walk(obj);
return pathVals;
}
const pathVals = toPathValues(lang);
// console.log(pathVals);
console.log("<root>");
for (let o of pathVals) {
// console.log(o);
console.log(` <key id="${o.path}">${o.value}</key>`);
}
console.log("</root>");
// <root>
// <key id="lang.oli.baseMapsTitle">Base maps</key>
// <key id="lang.oli.deviceLocation.showLocation">Show your location</key>
// <key id="lang.oli.fullScreen.tipLabel">Toggle full-screen</key>
// <key id="lang.oli.gazetteer.noResults">No results found</key>
// <key id="lang.oli.gazetteer.placeholder">Search...</key>
// <key id="lang.oli.gazetteer.queryTooShort">Type ${minQueryLength} or more characters for results</key>
// <key id="lang.oli.gazetteer.selectedOption">${selectedOption} ${index} of ${length} is highlighted</key>
// <key id="lang.oli.gazetteer.resultsDescription">Result count: ${length}. ${selectedOption}</key>
// <key id="lang.oli.gazetteer.assistiveHint">When autocomplete results are available, use the up and down arrows to review and enter to select. Users of touch devices can explore by touch or with swipe gestures.</key>
// <key id="lang.oli.layerSwitcher.hideButtonTitle">Collapse legend</key>
// <key id="lang.oli.layerSwitcher.showButtonTitle">Show legend</key>
// <key id="lang.oli.historyNavigation.backHtml">&lArr;</key>
// <key id="lang.oli.historyNavigation.backTitle">Navigate back</key>
// <key id="lang.oli.historyNavigation.forwardHtml">&rArr;</key>
// <key id="lang.oli.historyNavigation.forwardTitle">Navigate forward</key>
// <key id="lang.oli.zoom.zoomInTipLabel">Zoom in</key>
// <key id="lang.oli.zoom.zoomOutTipLabel">Zoom out</key>
// <key id="lang.oli.apps.spotlight.baseMapsTitle">Base layer</key>
// <key id="lang.oli.apps.spotlight.gazetteer.placeholder">Partial address or postcode...</key>
// </root>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment