Skip to content

Instantly share code, notes, and snippets.

@quickredfox
Created August 22, 2011 17:48
Show Gist options
  • Save quickredfox/1163022 to your computer and use it in GitHub Desktop.
Save quickredfox/1163022 to your computer and use it in GitHub Desktop.
en.js
// Load this file for the english version
var i18n_strings = {
"{0} is a great friend of mine": "{0} is a great friend of mine"
"some_key": "A string of text"
};
/*
Like Ext.String.format() except it translates the first argument before formating.
*/
Ext.apply( Ext.String, {
translate: function(){
var strkey = arguments[0];
arguments[0] = i18n_strings[ strkey ] || strkey;
return Ext.String.format.apply( null, arguments );
}
});
/// And you can setup some shortcut function
var __ = Ext.String.translate
// Load this file instead for the french version
var i18n_strings = {
"{0} is a great friend of mine": "C'est mon grand ami {0}"
"some_key": "Un peut de texte"
};
// examples usage:
Ext.create('Ext.panel.Panel', {
title: Ext.String.translate( "{0} is a great friend of mine", 'Roger' )
});
// or...
Ext.create('Ext.panel.Panel', {
title: __( "{0} is a great friend of mine", 'Roger' )
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment