Skip to content

Instantly share code, notes, and snippets.

@borantula
Last active May 7, 2020 09:43
Show Gist options
  • Save borantula/185f19ef7e77869d7b51043741306eb7 to your computer and use it in GitHub Desktop.
Save borantula/185f19ef7e77869d7b51043741306eb7 to your computer and use it in GitHub Desktop.
translation keys importer
/*
const data = [
{
"EN": "e.g. Art, Coins, Jewellery, Antiques, Cars",
"NL": "bijv. kunst, munten, sieraden, antiek, auto's",
"DE": "z.B. Kunst, Münzen, Schmuck, Antiquitäten, Autos",
"FR": "par exemple art, monnaies, bijoux, antiquités, voitures",
"IT": "per es. Arte, Monete, Gioielli, Antiquariato, Auto",
"ES": "por ejemplo, arte, monedas, joyería, antigüedades, coches",
"PT": "e.g. arte, moedas, jóias, antiguidades, carros",
"DA": "f.eks. Kunst, Mønter, Antikviteter, Biler",
"SV": "t ex. konst, mynt, smycken antikviteter och bilar",
"NO": "f.eks kunst, mynter, smykker, antikviteter, biler",
"PL": "np. sztuka, monety, biżuteria, antyki, samochody",
"ZH_CN": "",
"ZH_TW": "例如藝術,硬幣,珠寶,古董,汽車",
"HU": "pl. Művészet, Érmék, Ékszerek, Régiség, Autók",
"RO": "ex. Artă, Monede, Bijuterii, Antichități, Mașini",
"FI": "esim. taide, kolikot, korut, antiikki, autot",
"EL": "π.χ. Τέχνη, Νομίσματα, Κοσμήματα, Αντίκες, Αυτοκίνητα"
}
]
*/
function translationUpdater(data){
Object.keys(data[0]).forEach((lang)=>{
if(lang === "KEY") {
window["key"].value = data[0]["KEY"]
return;
}
const taId = lang.length === 2 ? `value_${lang.toLowerCase()}` : `value_${[...lang].map((a,k)=>k <= 1?a.toLowerCase():a).join('')}`
const textArea = document.getElementById(taId);
if(textArea){
const val = data[0][lang];
if(val.trim().length) {
textArea.value = val.trim();
}
}
})
window['add_translation_button'].removeAttribute('disabled')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment