BiStringBundle
This class is used to make creating multilingual applications easier. The string bundle is uses one hash table (objects in JavaScript) for every language and falls back on English ("en") in case the user language is not available.
This class extends BiEventTarget and therefore all methods and fields available for BiEventTarget are also available for BiStringBundle .
Constructor
new BiStringBundle ( )
Parameters
No parameters.
Properties
Methods
| Name | Description |
addBundle | Adds a bundle and associates that with a certain language code |
appendBundle | This adds key value pairs to an existing bundle. This allows you to modify an existing bundle with more strings |
getBundle | Returns the bundle (hash table) for the given language code. If fails an empty bundle will be returned. |
getBundleForLanguage | Returns the bundle (hash table) for the given language code. This will return the best match. If you pass "zh-CN" it will try to find the bundles in the following order; "zh-CN", "zh", language, majorLanguage, "en" and if all these fails an empty bundle (object) will be returned. |
getFormattedString | Returns the string for the given string id. The string is then formatted so that %1 to %n are replaced by the extra arguments to this method. This method does not allow you to specify the language. If that is needed use getString followed by formatString. |
getString | Returns the string for the given string id. The second argument is the language code to get the string for. If left out then the current language for the string bundle is used. |
getStringKeys | Returns the keys used to identify the strings in the bundles |
removeBundle | Removes the string bundle with the given language code |
Events
| Name | Type | Bubbles | Descripton |
change | | This event is fired when the current strings changes in some way. This happens when the language is changed or a new bundle is added with the current language. |
Static Methods
| Name | Description |
formatString | Takes a string containing %1 to %n and 0 to n extra arguments that will replace the %n strings. |
Static Fields
None.
Remarks
The string bundles (that are added using addBundle should be plain JavaScript objects (hash tables) with the following form: var enBundle = { languageCode: "en", languageName: "English", selectLanguage: "Select Language:", checkingForIsLoggedIn: "Checking if already logged in...", windowCaption: "Download the Bindowsu2122 Framework" }; The languageCode and languageName fields are not special in any way. It is just a good practice to include them and they are often useful to the application. Typical usage looks something like this: var stringBundle = new BiStringBundle; stringBundle.addBundle("en", enBundle); ... someLabel.setText(stringBundle.getString("someLabelText"));
Method Details
addBundle
Adds a bundle and associates that with a certain language code
Syntax
object.addBundle ( sLanguage,oStringMap ) Parameters
| Name | Type | Optional | Default | Descripton |
sLanguage | String | The language code for the string bundle to add. | ||
oStringMap | Object | The hash table used to map string identifiers to strings. |
Return Type
void
appendBundle
This adds key value pairs to an existing bundle. This allows you to modify an existing bundle with more strings
Syntax
object.appendBundle ( sLanguage,oStringMap ) Parameters
| Name | Type | Optional | Default | Descripton |
sLanguage | String | The language code for the string bundle to append. | ||
oStringMap | Object | The hash table used to map string identifiers to strings. |
Return Type
void
getBundle
Returns the bundle (hash table) for the given language code. If fails an empty bundle will be returned.
Syntax
object.getBundle ( [ sLanguage ] ) Parameters
| Name | Type | Optional | Default | Descripton |
sLanguage | String | ![]() | The language code of the string bundle to return. If left out the default language is used. |
Return Type
Object
getBundleForLanguage
Returns the bundle (hash table) for the given language code. This will return the best match. If you pass "zh-CN" it will try to find the bundles in the following order; "zh-CN", "zh", language, majorLanguage, "en" and if all these fails an empty bundle (object) will be returned.
Syntax
object.getBundleForLanguage ( [ sLanguage ] ) Parameters
| Name | Type | Optional | Default | Descripton |
sLanguage | String | ![]() | The language code of the string bundle to return. If left out the default language is used. |
Return Type
Object
getFormattedString
Returns the string for the given string id. The string is then formatted so that %1 to %n are replaced by the extra arguments to this method. This method does not allow you to specify the language. If that is needed use getString followed by formatString.
Syntax
object.getFormattedString ( sStringId [ ,args ] ) Parameters
| Name | Type | Optional | Default | Descripton |
sStringId | String | The id for the string to retreive | ||
args | String | ![]() | Optional arguments (as many as you wish) that will replace the '%n' in the pattern |
Return Type
String
getString
Returns the string for the given string id. The second argument is the language code to get the string for. If left out then the current language for the string bundle is used.
Syntax
object.getString ( sStringId [ ,sLanguage ] ) Parameters
| Name | Type | Optional | Default | Descripton |
sStringId | String | The id for the string to retreive | ||
sLanguage | String | ![]() | The language code of the string to return |
Return Type
String
getStringKeys
Returns the keys used to identify the strings in the bundles
Syntax
object.getStringKeys ( [ sLanguage ] ) Parameters
| Name | Type | Optional | Default | Descripton |
sLanguage | String | ![]() | The language code to use when getting the strings in the bundle. If left out the current language is is used |
Return Type
String[]
removeBundle
Removes the string bundle with the given language code
Syntax
object.removeBundle ( sLanguage ) Parameters
| Name | Type | Optional | Default | Descripton |
sLanguage | String | The language code of the string bundle to remove |
Return Type
void
Static Method Details
formatString
Takes a string containing %1 to %n and 0 to n extra arguments that will replace the %n strings.
Syntax
BiStringBundle . formatString ( sPattern [ ,args ] ) Parameters
| Name | Type | Optional | Default | Descripton |
sPattern | String | A string containing '%n' where '%n' will be replaced by the remaining arguments. | ||
args | String | ![]() | Optional arguments (as many as you wish) that will replace the '%n' in the pattern |
Return Type
String
