Class Country
Create a new country information instance. Instances of this class encode information about country name.
The options can contain any of the following properties:
- locale - specify the locale for this instance. Country names are provided in the language of this locale.
- onLoad - a callback function to call when the country name data is fully loaded. When the onLoad option is given, this class will attempt to load any missing locale data using the ilib loader callback. When the constructor is done (even if the data is already preassembled), the onLoad function is called with the current instance as a parameter, so this callback can be used with preassembled or dynamic loading or a mix of the two.
- sync - tell whether to load any missing locale data synchronously or asynchronously. If this option is given as "false", then the "onLoad" callback must be given, as the instance returned from this constructor will not be usable for a while.
- loadParams - an object containing parameters to pass to the loader callback function when locale data is missing. The parameters are not interpretted or modified in any way. They are simply passed along. The object may contain any property/value pairs as long as the calling code is in agreement with the loader callback function as to what those parameters mean.
Defined in: Country.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Country(options)
|
Method Attributes | Method Name and Description |
---|---|
<static> |
Country.getAvailableCode()
Return an array of the ids for all ISO 3166-1 alpha-2 code that
this copy of ilib knows about.
|
<static> |
Country.getAvailableCountry()
Return an array of country names that this copy of ilib knows about.
|
getCode(ctryname)
Return the country code corresponding to the country name given.
|
|
Return the locale for this country.
|
|
getName(code)
Return the country name corresponding to the country code given.
|
Class Detail
Country(options)
- Parameters:
- options
- {Object} a set of properties to govern how this instance is constructed.
Method Detail
<static>
{Object}
Country.getAvailableCode()
Return an array of the ids for all ISO 3166-1 alpha-2 code that
this copy of ilib knows about.
- Returns:
- {Object} an object of country code that this copy of ilib knows about.
<static>
{Object}
Country.getAvailableCountry()
Return an array of country names that this copy of ilib knows about.
- Returns:
- {Object} an object of country code that this copy of ilib knows about.
{string}
getCode(ctryname)
Return the country code corresponding to the country name given.
If the country name is given, but it is not found in the list of known countries, this
method will throw an exception.
- Parameters:
- {string} ctryname
- The country name in the language of the locale of this instance
- Throws:
- "Country xx is unknown" when the given country name is not in the list of known country names. xx is replaced with the requested country name.
- Returns:
- {string} the country code corresponding to the country name
{Locale}
getLocale()
Return the locale for this country. If the options to the constructor
included a locale property in order to find the country that is appropriate
for that locale, then the locale is returned here. If the options did not
include a locale, then this method returns undefined.
- Returns:
- {Locale} the locale used in the constructor of this instance, or undefined if no locale was given in the constructor
{string}
getName(code)
Return the country name corresponding to the country code given.
If the code is given, but it is not found in the list of known countries, this
method will throw an exception.
- Parameters:
- {string} code
- The country code to get the country name
- Throws:
- "Country xx is unknown" when the given country code is not in the list of known country codes. xx is replaced with the requested country code.
- Returns:
- {string} the country name in the language of the locale of this instance