Skip to content

Instantly share code, notes, and snippets.

@Steven-Sanseau
Last active September 26, 2019 13:43
Show Gist options
  • Save Steven-Sanseau/bd3b03acdede56d9dc7718603ad7a06c to your computer and use it in GitHub Desktop.
Save Steven-Sanseau/bd3b03acdede56d9dc7718603ad7a06c to your computer and use it in GitHub Desktop.
I18n Key missing Finder
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