Skip to content

Instantly share code, notes, and snippets.

@oleander
Created June 28, 2012 23:28
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oleander/6a3f1b3a4cf8de889e34 to your computer and use it in GitHub Desktop.
Save oleander/6a3f1b3a4cf8de889e34 to your computer and use it in GitHub Desktop.
/*
t("products.price");
*/
$(function() {
window.t = function(key) {
if(!key){
return "N/A";
}
var keys = key.split(".");
var comp = window.I18n;
$(keys).each(function(_, value) {
if(comp){
comp = comp[value];
}
});
if(!comp && console){
console.debug("No translation found for key: " + key);
return "N/A";
}
return comp;
};
});
@kerunaru
Copy link

kerunaru commented Jan 7, 2015

Maybe this should detects automatically the current app locale.
Just change line 11 from this:

var comp = window.I18n;

To this:

var comp = window.I18n.<%= I18n.locale %>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment