Last active
June 7, 2016 22:44
-
-
Save dansleboby/df4fbcf2cb2cf56cf4c5095624066b85 to your computer and use it in GitHub Desktop.
Change language of Snipcart with Javascript
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 SnipcartLanguage(lang) { | |
if(jQuery.inArray(lang, Snipcart.locales) !== -1) { | |
if(jQuery.inArray(lang, Object.keys(Snipcart.i18n._locales)) !== -1) { | |
console.log("Change language to: " + lang); | |
Snipcart.i18n.lang(lang); | |
} else { | |
console.log("Download language "+lang+" ..."); | |
//From github: https://cdn.rawgit.com/snipcart/snipcart-localization/master/locales/ | |
jQuery.getScript("https://cdn.snipcart.com/scripts/2.0/snipcart/l10n/locales/" + lang + ".js").done(function() { | |
console.log("Download complete for "+lang+"!"); | |
SnipcartLanguage(lang); | |
}); | |
} | |
} else { | |
console.log("Language ["+lang+"] not valid, allowed:"); | |
console.log(Snipcart.locales); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment