Keeps track of the user locale, by auto-detecting the browser language, allowing a user selection, and automatically modifying any url that runs through the CacheManager.
springroll.Languages
config
config
Object
The language settings to be used.
default
String
The default language name to use if asked for one that is not present.
languages
Array
An array of all supported languages, with entries being locale ids (dialects allowed). Locale ids should be lower case.
[replace="%LANG%"]
String
optional
A string to replace in urls with the current language.
getFormattedString
key
args
Gets a formatted string from the current string table. See String.format() in the Core module.
The translated string.
getPreferredLanguages
Gets the preferred languages from the browser.
The list of preferred languages in order of preference.
getString
key
Gets a string from the current string table.
key
String
The key of the string to get.
The translated string.
has
name
[callback]
Checks if the EventDispatcher has a specific listener or any listener for a given event.
If the EventDispatcher has the specified listener.
modifyUrl
url
Modifies a url, replacing a specified value with the current language.
url
String
The url to modify to a language specific version.
off
name
callback
Remove the event listener
Return this EventDispatcher for chaining calls.
on
name
callback
[priority=0]
Add an event listener. The parameters for the listener functions depend on the event.
name
String | Object
The type of event (can be multiple events separated by spaces), or a map of events to handlers
callback
Function | Array*
The callback function when event is fired or an array of callbacks.
[priority=0]
Int
optional
The priority of the event listener. Higher numbers are handled first.
Return this EventDispatcher for chaining calls.
once
name
callback
[priority=0]
Add an event listener but only handle it one time.
name
String | Object
The type of event (can be multiple events separated by spaces), or a map of events to handlers
callback
Function | Array*
The callback function when event is fired or an array of callbacks.
[priority=0]
Int
optional
The priority of the event listener. Higher numbers are handled first.
Return this EventDispatcher for chaining calls.
setConfig
config
Configure
config
Object
The language settings to be used.
default
String
The default language name to use if asked for one that is not present.
languages
Array
An array of all supported languages, with entries being locale ids (dialects allowed). Locale ids should be lower case.
[replace="%LANG%"]
String
optional
A string to replace in urls with the current language.
setLanguage
languageList
Sets the current language, based on specified preferences and what is available.
setStringTable
dictionary
Sets the string table for later reference.
dictionary
Dictionary
The string table, with keys that you would use to reference the translations.
trigger
type
arguments
Dispatch an event
type
String
The type of event to trigger
arguments
Additional parameters for the listener functions.
changed
Fired when the chosen language has changed.
language
String
The newly chosen language.