Created
November 20, 2015 17:48
-
-
Save hugohil/b4665fc8d9bce2d867df to your computer and use it in GitHub Desktop.
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
i18n.init({ lng: 'en-EN', load: 'current', fallbackLng: false }, function(t) { | |
var keys = document.querySelectorAll('[data-i18n]'); | |
for (var i = 0; i < keys.length; i++) { | |
var key = keys[i].dataset.i18n; | |
var attribute = null; | |
var attributeRegEx = new RegExp(/\[(\S*)\]/); | |
if(key.match(attributeRegEx)){ | |
attribute = key.match(attributeRegEx)[1]; | |
key = key.replace(attributeRegEx, ''); | |
} | |
var translation = i18n.t(key); | |
if(translation){ | |
if(!attribute){ | |
keys[i].innerHTML = translation; | |
} else { | |
keys[i].setAttribute(attribute, translation); | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment