Last active
October 15, 2025 14:58
-
-
Save walkermatt/b9fb5cb737117e11ef066c2c7e8eda7f to your computer and use it in GitHub Desktop.
Transform iShare language strings in JSON format to XML format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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">⇐</key> | |
| // <key id="lang.oli.historyNavigation.backTitle">Navigate back</key> | |
| // <key id="lang.oli.historyNavigation.forwardHtml">⇒</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