Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dansleboby/df4fbcf2cb2cf56cf4c5095624066b85 to your computer and use it in GitHub Desktop.
Save dansleboby/df4fbcf2cb2cf56cf4c5095624066b85 to your computer and use it in GitHub Desktop.
Change language of Snipcart with Javascript
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