Last active
September 26, 2019 13:43
-
-
Save Steven-Sanseau/bd3b03acdede56d9dc7718603ad7a06c to your computer and use it in GitHub Desktop.
I18n Key missing Finder
This file contains 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
function setValue(object, path, value) { | |
const keys = path.split('.') | |
const last = keys.pop() | |
keys.reduce((o, k) => { | |
return (o[k] = o[k] || {}) | |
}, object)[last] = value | |
} | |
function writeNewTransKey(key) { | |
const file = localStorage.getItem('trad') | |
if (!file) { | |
localStorage.setItem('trad', JSON.stringify({})) | |
} | |
const data = JSON.parse(file) | |
setValue(data, key, '##MISSING') | |
localStorage.setItem('trad', JSON.stringify(data)) | |
} | |
GlobalI18n.missingTranslation = key => writeNewTransKey(key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment