API Documentation for: 1.0.5
Show:

Translate Class

Defined in: Translate:6
Namespace: cloudkid

Internationalization/translation object with convenient jquery plugin

Item Index

Methods

Properties

Methods

$.fn._f

(
  • [attr="src"]
)
Element static

Defined in $.fn._f:408

Allows you to swap an localized file path with jQuery selector. See window._f for more information.

$('img#example')._f()

Parameters:

  • [attr="src"] String optional

    The attribute to change the file for

Returns:

Element:

Chained and translated element(s).

$.fn._t

(
  • key
  • [params]
)
Element static

Defined in $.fn._t:367

Allows you to translate a jQuery selector. See window._t for more information.

$('h1')._t('some text')

Parameters:

  • key String

    The string to translate .

  • [params] Mixed optional

    Params for using printf() on the string.

Returns:

Element:

Chained and translated element(s).

autoDetect

(
  • [useCountryLocale=true]
)
Array | String static

Defined in autoDetect:168

Auto detect the locale based on the window navigator object

Parameters:

  • [useCountryLocale=true] Boolean optional

    If we should use the country locale (e.g., "en-US") as well as the language.

Returns:

Array | String:

The new locale selected, returns a string if useCountryLocale is false.

getLocales

() Array private static

Defined in getLocales:250

Get the locales with the fallback

Returns:

Array:

The collection of locales where the first index is the highest priority

load

(
  • dict
  • [langOrCallback]
  • [callback]
)
Translate static

Defined in load:61

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:

  • dict Object | String

    The translation dictionary or file path to the translation dictionary

  • [langOrCallback] String | Function optional

    Either the language code or the function callback for file loading

  • [callback] Function optional

    The methond to callback if we're loading a file

Returns:

Translate:

The Translate object for chaining

printf

(
  • str
  • args
)
String private

Defined in printf:341

Substitutes %s with parameters given in list. %%s is used to escape %s.

Parameters:

  • str String

    String to perform printf on.

  • args String

    Array of arguments for printf.

Returns:

String:

Substituted string

refresh

() private static

Defined in refresh:222

Rebuild the current dictionary of translations to use

reset

() Translate static

Defined in reset:152

Remove all of the current dictionaries stored and the saved locale

Returns:

Translate:

The Translate object for chaining

translateFile

(
  • file
)
String private

Defined in translateFile:303

Converts a file to a localized version using the first locale. If no locale is set, returns the original file.

Parameters:

Returns:

String:

The updated file path containing local

translateString

(
  • key
  • params..
)
String private static

Defined in translateString:270

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:

  • key String

    The translation key look-up to translate.

  • params.. Object

    params for using printf() on the string.

Returns:

String:

Translated word.

window._f

(
  • file
)
String static

Defined in window._f:441

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:

Returns:

String:

The updated file path containing local

window._t

(
  • str
  • [params*]
)
String static

Defined in window._t:430

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 String

    The string to translate.

  • [params*] Mixed optional

    params for using printf() on the string.

Returns:

String:

Translated word.

Properties

_current

Object private static

Defined in _current:29

The current set of translations to use

_dict

Object private static

Defined in _dict:21

The full language dictionary containing all languages as keys

_fallbackLocale

String private static

Defined in _fallbackLocale:45

The fallback locale if no translation is found

_locale

String | Array private static

Defined in _locale:37

The currently selected locale

_slice

Function private static

Defined in _slice:53

Reference to the slice method

fallbackLocale

String static

Defined in fallbackLocale:186

The optional fallback locale to use in all cases

fileSeparator

String static

Defined in fileSeparator:142

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: "_"

locale

String | Array static

Defined in locale:204

The current ISO-639-1 two-letter language locale

VERSION

String static

Defined in VERSION:13

The current version of the plugin