# new ResBundle(optionsnullable)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
Object
|
<nullable> |
Options controlling how the bundle is created |
Methods
# containsKey(sourceopt, nullable, keyopt, nullable) → {boolean}
Return true if the current bundle contains a translation for the given key and source. The getString method will always return a string for any given key and source combination, so it cannot be used to tell if a translation exists. Either one or both of the source and key must be specified. If both are not specified, this method will return false.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
source |
string
|
<optional> <nullable> |
source string to look up |
key |
string
|
<optional> <nullable> |
key to look up |
true if this bundle contains a translation for the key, and false otherwise
boolean
# getLocale() → {Locale}
Return the locale of this resource bundle.
the locale of this resource bundle object
# getName() → {string}
Return the name of this resource bundle. This corresponds to the name option given to the constructor.
name of the the current instance
string
# getResObj() → {Object}
Return the merged resources as an entire object. When loading resources for a locale that are not just a set of translated strings, but instead an entire structured javascript object, you can gain access to that object via this call. This method will ensure that all the of the parts of the object are correct for the locale.
For pre-assembled data, it starts by loading ilib.data[name], where name is the base name for this set of resources. Then, it successively merges objects in the base data using progressively more locale-specific data. It loads it in this order from ilib.data:
- language
- region
- language_script
- language_region
- region_variant
- language_script_region
- language_region_variant
- language_script_region_variant
For dynamically loaded data, the code attempts to load the same sequence as above, but with slash path separators instead of underscores.
Loading the resources this way allows the program to share resources between all locales that share a common language, region, or script. As a general rule-of-thumb, resources should be as generic as possible in order to cover as many locales as possible.
returns the object that is the basis for this resources instance
Object
# getString(source, key, escapeModeopt, nullable) → {IString|Array.<IString>|undefined}
Return a localized string, array, or object. This method can localize individual strings or arrays of strings.
If the source parameter is a string, the translation of that string is looked up and returned. If the source parameter is an array of strings, then the translation of each of the elements of that array is looked up, and an array of translated strings is returned.
If any string is not found in the loaded set of resources, the original source string is returned. If the key is not given, then the source string itself is used as the key. In the case where the source string is used as the key, the whitespace is compressed down to 1 space each, and the whitespace at the beginning and end of the string is trimmed.
The escape mode specifies what type of output you are escaping the returned string for. Modes are similar to the types:
- "html" -- prevents HTML injection by escaping the characters < > and &
- "xml" -- currently same as "html" mode
- "js" -- prevents breaking Javascript syntax by backslash escaping all quote and double-quote characters
- "attribute" -- meant for HTML attribute values. Currently this is the same as "js" escape mode.
- "default" -- use the type parameter from the constructor as the escape mode as well
- "none" or undefined -- no escaping at all.
The type parameter of the constructor specifies what type of strings this bundle is operating upon. This allows pseudo-translation and automatic key generation to happen properly by telling this class how to parse the string. The escape mode for this method is different in that it specifies how this string will be used in the calling code and therefore how to escape it properly.
For example, a section of Javascript code may be constructing an HTML snippet in a string to add to the web page. In this case, the type parameter in the constructor should be "html" so that the source string can be parsed properly, but the escape mode should be "js" so that the output string can be used in Javascript without causing syntax errors.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
source |
string
|
Array.<string>=
|
the source string or strings to translate |
|
key |
string
|
Array.<string>=
|
optional name of the key, if any |
|
escapeMode |
string
|
<optional> <nullable> |
escape mode, if any |
# getStringJS(source, key, escapeModeopt, nullable) → {string|Array.<string>|undefined}
Return a localized string as an intrinsic Javascript String object. This does the same thing as the getString() method, but it returns a regular Javascript string instead of and IString instance. This means it cannot be formatted with the format() method without being wrapped in an IString instance first.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
source |
string
|
Array.<string>=
|
the source string to translate |
|
key |
string
|
Array.<string>=
|
optional name of the key, if any |
|
escapeMode |
string
|
<optional> <nullable> |
escape mode, if any |
the translation of the given source/key or undefined if the translation is not found and the source is undefined
string
|
Array.<string>
|
undefined
# getType() → {string}
Return the type of this resource bundle. This corresponds to the type option given to the constructor.
type of the the current instance
string