Translate Class
Internationalization/translation object with convenient jquery plugin
Item Index
Methods
- $.fn._f static
- $.fn._t static
- autoDetect static
- getLocales static
- load static
- printf
- refresh static
- reset static
- translateFile
- translateString static
- window._f static
- window._t static
Properties
- _current static
- _dict static
- _fallbackLocale static
- _locale static
- _slice static
- fallbackLocale static
- fileSeparator static
- locale static
- VERSION static
Methods
$.fn._f
-
[attr="src"]
Allows you to swap an localized file path with jQuery selector. See window._f for more information.
$('img#example')._f()
Parameters:
-
[attr="src"]
String optionalThe attribute to change the file for
Returns:
Chained and translated element(s).
$.fn._t
-
key
-
[params]
Allows you to translate a jQuery selector. See window._t for more information.
$('h1')._t('some text')
Parameters:
-
key
StringThe string to translate .
-
[params]
Mixed optionalParams for using printf() on the string.
Returns:
Chained and translated element(s).
autoDetect
-
[useCountryLocale=true]
Auto detect the locale based on the window navigator object
Parameters:
-
[useCountryLocale=true]
Boolean optionalIf we should use the country locale (e.g., "en-US") as well as the language.
getLocales
()
Array
private
static
Get the locales with the fallback
Returns:
The collection of locales where the first index is the highest priority
load
-
dict
-
[langOrCallback]
-
[callback]
Load the full dictionary containing all translations, this can also be used to load separate JSON files which contain the translation. Each JSON file can contain keys matching the locale which to use, or a single locale:
// Load external json for all locales
Translate.load("lang.json", function(){
// Finished loading
});
// Or load all locales directly
var dict = {
"en" : {
"title" : "My Site"
}
};
Translate.load(dict);
// Or loading a single local externally
Translate.load("locale/en/lang.json", "en", function(){
// Finished loading
});
// Or load a single local directly
var dict = {
"title" : "My Site"
};
Translate.load(dict, "en");
Parameters:
Returns:
The Translate object for chaining
printf
-
str
-
args
Substitutes %s with parameters given in list. %%s is used to escape %s.
Returns:
Substituted string
refresh
()
private
static
Rebuild the current dictionary of translations to use
reset
()
Translate
static
Remove all of the current dictionaries stored and the saved locale
Returns:
The Translate object for chaining
translateFile
-
file
Converts a file to a localized version using the first locale. If no locale is set, returns the original file.
Parameters:
-
file
StringThe file path
Returns:
The updated file path containing local
translateString
-
key
-
params..
Looks the given string up in the dictionary and returns the translation if one exists. If a translation is not found, returns the original word.
Parameters:
Returns:
Translated word.
window._f
-
file
Converts a file to a localized version using the locale preferences. If no locale is set or no valid files are found, returns the original file.
Parameters:
-
file
StringThe file path
Returns:
The updated file path containing local
window._t
-
str
-
[params*]
Looks the given string up in the dictionary and returns the translation if one exists. If a translation is not found, returns the original word.
Parameters:
-
str
StringThe string to translate.
-
[params*]
Mixed optionalparams for using printf() on the string.
Returns:
Translated word.
Properties
fileSeparator
String
static
The separator between the file name and the locale if using the filename translation. For instance, "myfile.png" becomes "myfile_en-US.png" joining "myfile" with the separator, locale then file extension.
Default: "_"