kony.i18n Namespace
The kony,i18n Namespace, which forms the Internationalization API, provides the following API elements.
NOTE: From V8 SP4 onwards, the i18n database data for a Quantum App child app is stored in child app data and not under the parent app. This feature is applicable for iOS and Android platforms.
Functions
The kony.i18n namespace, which is used for internationalization, provides the following functions.
This API allows you to delete an existing resource bundle. If a resource bundle does not exist, the API returns without performing any operation. Only resource bundles which are newly created using the setResourceBundle API will be deleted. The bundle which are created by IDE, cannot be deleted, but they can only be updated.
Syntax
kony.i18n.deleteResourceBundle(locale);
Input Parameters
Parameter | Description |
---|---|
locale [String] - Mandatory | Specifies the locale for which the resource bundle needs to be deleted. |
Example
//To delete the resource bundle deleteResourceBundle: function() { kony.i18n.deleteResourceBundle("de_DE"); alert(" Resources bundle has been deleted."); },
Return Values
None
Exceptions
1300 - i18n error or Locale not supported error
Platform Availability
Available on all platforms.
This API returns the locale (string) that is currently being used by the application to populate the localized data. This locale might be different than the system locale. The locale follows the format language_Country. For example, en_US
. Country
is not mandatory.
Use Cases
You can use this API to know the current locale of the application before:
- changing the locale.
- deleting the resource bundle of the locale.
Syntax
Input Parameters
None
Example
//To get the Locale name that is set on your app
getCurrentLocale:functio(){ var currentLocales = kony.i18n.getCurrentLocale(); alert("CurrentLocale :" + currentLocales); },
Return Values
Return Value | Description |
---|---|
Current locale [String] | The current locale that is being used by the application is returned. |
Exceptions
1300 - i18n error or Locale not supported error
Implementation Details
The current locale of the application is identified using the following rules:
Device Locale | Locales Supported by the application | Default Locale | Locale returned by getCurrentLocale API |
---|---|---|---|
en_GB | en_US, zh_TW | en_TW | en_TW (Since the device locale is not supported by the application, the API falls back to default locale) |
en_US | en_US, en , zh_TW | en_TW | en_US (Since the device locale is supported by the application, the API returns it as the current locale) |
en_US | en, zh_TW | en_TW | en (Since the device locale is supported by the application, the API falls back to the country) |
This API uses the following rules to identify the current locale:
- When the device locale is not supported by the app:
For example, if the device locale is set as en_GB, the app supports fr_GR and nl_NL, and the default locale is set as nl_NL in Quantum Visualizer, then the kony.i18n.getCurrentLocale() API returns nl_NL. When the device locale supports the language but does not support the region:
For example, if the device locale is set as en, the app supports fr_GR, en_US, en_GB, and nl_NL, and the default locale is set as nl_NL in Quantum Visualizer, then the kony.i18n.getCurrentLocale() API picks up the first locale that matches the language. In this example, the API returns en_US as it is the first locale that matches the language as specified in the device system settings.NOTE: On iPhone and Android, the device settings mandate that a region must also be associated with a language.
- When appropriate fonts are not installed on the device for a given locale:
For example, if the device locale is set as en_GB, the app supports fr_GR and nl_NL, and the default locale is set as nl_NL in Quantum Visualizer, then the kony.i18n.getCurrentLocale() API returns nl_NL. If the device does not have Dutch fonts installed, the application UI displays junk characters.
Platform Availability
Available on all platforms.
This API provides you the ability to fetch the current locale of the device.
Syntax
kony.i18n.getCurrentDeviceLocale();
Input Parameters
None
Example
//To get the current device locale
getCurrentDeviceLocale:function(){ var locale = kony.i18n.getCurrentDeviceLocale(); alert("current device locale is " + locale); },
Return Values
Return Value | Description |
---|---|
listOfLocales [Table] |
A table with the following key-value pairs is returned:
For example, Where myLocaleDetails={language="en", country="US", name="English US"} |
NOTE: In iOS platform this API returns a string value.
Exceptions
1300 - i18n error or Locale not supported error
Platform Availability
- iOS
- Android
This API returns the localized string that corresponds to the specified i18n Key.
Syntax
kony.i18n.getLocalizedString(i18nkey);
Input Parameters
Parameter | Description |
---|---|
i18nkey [String]- Mandatory | Specifies the internationalization key for which the localized string needs to be returned. |
Example
//To get the localized string that corresponds to the specified i18n Key. getLocalizedString: function() { var currentLocale = kony.i18n.getLocalizedString("Hello"); alert(" LocalizedString Method called :" + currentLocale); },
Return Values
Return Value | Description |
---|---|
Localizedstring [String] | Returns the localized string corresponding to the key value. |
Exceptions
1300 - i18n error or Locale not supported error
Platform Availability
Available on all platforms.
This API retrieves a list of all the locales supported by the device.
Syntax
kony.i18n.getSupportedLocales();
Input Parameters
None
Example
//To get all the locales supported by the device getSupportedLocale: function() { var supportedLocales = kony.i18n.getSupportedLocales(); alert("Supported Locales :" + JSON.stringify(supportedLocales)); },
Return Values
Return Value | Description |
---|---|
listOfLocales [Table] |
A table with the following key-value pairs is returned:
For example, Where list={{language:"en", country:"US", name:"English US"},{language:"en", country:"UK", name:"English UK"}} |
Exceptions
1300 - i18n error or Locale not supported error
Platform Availability
Available on all platforms except Desktop Web*.
*Desktop Web returns only current locale instead of all locales supported by the browser.
This API provides you the ability to view whether a locale is supported by a device.
Syntax
kony.i18n.isLocaleSupportedByDevice(locale);
Input Parameters
Parameter | Description |
---|---|
locale [String] - Mandatory |
Specifies the locale that must be verified if it is supported by the device. locale must be in one of the following formats:
For example, kony.i18n.isLocaleSupportedByDevice("fr") |
Example
//To check whether the specified locale is supported by the device or not. Checkthelocale: function() { var a = this.view.txtbx.text; if (kony.i18n.isLocaleSupportedByDevice("a") === true) { alert("This locale is supported"); } else { alert("This Locale is not supported"); } },
Return Values
Return Value | Description |
---|---|
status [Boolean] |
Indicates the status if the specified locale is supported by the device.
|
Exceptions
1300 - i18n error or Locale not supported error
Platform Availability
Available on all platforms except Desktop Web.
This API checks if a resource bundle exists for a given locale and returns a boolean value.
Syntax
kony.i18n.isResourceBundlePresent (locale);
Input Parameters
Paramater | Description |
---|---|
locale [String] - Mandatory | Specifies the locale for which the resource bundle is checked. |
Example
isResourceBundlePresent: function() { try { var exists = kony.i18n.isResourceBundlePresent("en_GB"); alert("English resource bundle is present " + exists); } catch (i18nError) { alert("Exception While getting isResourceBundlePresent : " + i18nError); } },
Return Values
Return Value | Description |
---|---|
status [Boolean] | true - if the resource bundle exists for the given locale. false - if no resource bundle exists for the given locale. |
Exceptions
1300 - i18n error or Locale not supported error
Platform Availability
Available on all platforms except Desktop Web.
Every application that has support for internationalization needs a locale to be set as a default locale. This API allows you to set the specified locale as the default locale for the application. You can also set the default locale from the IDE. However, this API allows you to perform that task dynamically.
You must set the resource bundle for a given locale to have internationalization support for that locale.
Syntax
kony.i18n.setDefaultLocaleAsync(localename, onsuccesscallback, onfailurecallback, info);
Input Parameters
Parameter | Description |
---|---|
localename [String] - Mandatory |
Specifies the locale that must be set as the default locale of the application. |
onsuccesscallback [Function] - Mandatory |
onsuccess callback is called by the platform after successfully setting the specified locale as default. onsucess(oldlocalename, newlocalename){ \\code } |
onfailurecallback [Function] - Mandatory |
onfailure callback will be called by the platform if the locale is not set successfully. onfailure (errCode, errMsg){ \\code } |
info [Object] - Optional |
A JavaScript object consisting of key value pairs. If info parameter is specified, it is passed to the callback function as a last parameter. If the info parameter is not specified, the callback function receives the info as null/nil. "Info" is basically a user data where in the application developers will pass it to the async API's and the platform returns this info object to the corresponding async callback. This parameter is helpful for developers to remember the context when the methods are called in asynchronous fashion.Developers can define any custom keys and values within the info Object based on the needs. These are not predefined keys with values. |
Example
//To set the default locale for your app. setDefaultLocaleAsync: function(){ kony.i18n.setDefaultLocaleAsync("fr_FR", this.onsuccesscallback, this.onfailurecallback); },
Return Values
None
Exceptions
1300 - i18n error or Locale not supported error
Platform Availability
Available on all platforms.
This API provides you the ability to set the specified locale as the current locale of the application. If the locale is not supported by the device, junk characters are displayed on the screen for the locale specific string.
You must set the resource bundle for a given locale to have internationalization support for that locale.
Syntax
kony.i18n.setCurrentLocaleAsync(localename, onsuccesscallback, onfailurecallback, info);
Input Parameters
Parameter | Description |
---|---|
localename [String] - Mandatory |
Specifies the locale that must be set as the default locale of the application. |
onsuccesscallback [Function] - Mandatory | onsuccess callback will be called by the platform after a locale is set successfully as the current locale.onsucess(oldlocalename, newlocalename){ \\code } |
onfailurecallback [Function] - Mandatory | onfailure callback will be called by the platform if the locale is not set successfully.onfailure (errCode, errMsg){ \\code } |
info [Object] - Optional |
A JavaScript object consisting of key value pairs. If info parameter is specified, it is passed to the callback function as a last parameter. If the info parameter is not specified, the callback function receives the info as null/nil. "Info" is basically a user data where in the application developers will pass it to the async API's and the platform returns this info object to the corresponding async callback. This parameter is helpful for developers to remember the context when the methods are called in asynchronous fashion.Developers can define any custom keys and values within the info Object based on the needs. These are not predefined keys with values. |
Example
/*By using this function, you set a locale based on your input that you select from the list box widget.*/ setlocaleListbox: function() { if (this.view.lstbx.selectedKey == "lb1") { kony.i18n.setCurrentLocaleAsync("en_GB", this.onsuccesscallback, this.onfailurecallback); } else if (this.view.lstbx.selectedKey == "lb2") { kony.i18n.setCurrentLocaleAsync("es_AR", this.onsuccesscallback, this.onfailurecallback); } else if (this.view.lstbx.selectedKey == "lb3") { kony.i18n.setCurrentLocaleAsync("fr_FR", this.onsuccesscallback, this.onfailurecallback); } },
Return Values
None
Exceptions
1300 - i18n error or Locale not supported error
Platform Availability
Available on all platforms.
This API helps you to define the Right-To-Left (RTL) behavior for each locale in an application.
NOTE: When the application calls the kony.i18n.setDefaultLocaleAsync API, Quantum Visualizer Framework loads forms with the corresponding Locale.The forms that were loaded previously must be destroyed in application code to see the effect of the RTL/LTR feature for that particular form.
Syntax
kony.i18n.setLocaleLayoutConfig({ "<locale_key1>" : {"mirrorFlexPositionProperties","mirrorContentAlignment", "mirrorFlowHorizontalAlignment":});
Input Parameters
Parameter | Description |
---|---|
mirrorFlexPositionProperties [Boolean] - Mandatory |
This property reverses the layout properties for left and right alignment. At run time the framework iterates through all the widgets in any given form and if the layout is set to RTL(mirrorFlexPositionProperties = true), the following actions are performed:
|
mirrorContentAlignment [Boolean] - Mandatory |
This property reverses the content alignment from right to left. At run time the framework iterates through all the widgets in any given form and if the layout is set to RTL(mirrorContentAlignment = true), the following actions are performed:
|
mirrorFlowHorizontalAlignment [Boolean] - Mandatory | This property converts the flow horizontal alignment of a FlexContainer from left to right. Quantum Visualizer Framework internally applies the NOT operator on the reverseLayoutDirection Property of horizontal FlexContainer to change the alignment. |
Example
kony.i18n.setLocaleLayoutConfig({ "<locale_key1>": { "mirrorFlexPositionProperties": true / false, "mirrorContentAlignment": true / false, "mirrorFlowHorizontalAlignment": true / false, }, "<locale_key2>": { "mirrorFlexPositionProperties": true / false, "mirrorContentAlignment": true / false, "mirrorFlowHorizontalAlignment": true / false, }, });
Properties | Local flag value | Widget flag value | Action |
---|
Platform Availability
- iOS
- Android
This API allows you to set the specified resource bundle for a given locale. If the specified locale has a resource bundle already set, it is overridden with the given resource bundle.
If no resource bundle has been set previously, this API will create a new resource bundle.
You must set the resource bundle for a given locale to have internationalization support for that locale.
Syntax
kony.i18n.setResourceBundle(inputtable, locale);
Input Parameters
Paramater | Description |
---|---|
inputtable [Table] - Mandatory | Specifies the resource bundle that needs to be set for the given locale. |
locale [String] - Mandatory | Specifies the locale for which the resource bundle needs to be set. |
Example
//To set a resource bundle for the key "Hello" setResourceBundle: function(){ kony.i18n.setResourceBundle({ Hello: "Hallo Welt", }, "de_DE"); kony.i18n.setCurrentLocaleAsync("de_DE",this.onsuccesscallback, this.onfailurecallback); },
Return Values
None
Exceptions
1300 - i18n error or Locale not supported error, Locale not supported.
Platform Availability
Available on all platforms.
This API allows you to append new key-value pairs to the given resource bundle for a specified locale. The key-value pairs you provide will be appended at the end of the resource bundle.
If no resource bundle exists for the specified locale, a new resource bundle is created.
Syntax
kony.i18n.updateResourceBundle(inputtable, locale);
Input Parameters
Paramater | Description |
---|---|
inputtable [Table] - Mandatory | Specifies the resource bundle that needs to be set for the given locale. |
locale [String] - Mandatory | Specifies the locale for which the resource bundle needs to be set. |
Example
//To update the resource bundle with a different text updateResourceBundle: function(){ kony.i18n.updateResourceBundle({ Hello: "Hallo Leute", }, "de_DE"); kony.i18n.setCurrentLocaleAsync("de_DE",this.onsuccesscallback1, this.onfailurecallback); },
Return Values
None
Exceptions
1300 - i18n error or Locale not supported error
Platform Availability
Available on all platforms.
Deprecated Functions
The following APIs have been deprecated from 5.0 onwards and are only supported for backward compatibility.
This API provides you the ability to set the specified locale as the current locale of the application. If the locale is not supported by the device, junk characters will be displayed on the screen for the locale specific string.
Syntax
kony.i18n.setCurrentLocale(locale);
Input Parameters
locale [String] - Mandatory
Specifies the locale that must be set as the current locale of the application
Return Values
errorcode [Number]
A number that denotes the error.
- 0 - Locale is successfully applied
- 100 - The supplied locale is not available in the device.
- 101 - The supplied locale is not available in application
Error Codes
- 100 - if the locale is not supported by device
- 101 - if the locale is supported by device but not by the application
Implementation Details
This section explains how this API is implemented. This API:
- sets the appropriate display language and region for displaying content and images in the application
- sets the specified locale as the input locale (keyboard and calendar display) if the specified locale is available - on Android
- displays junk characters for the locale specific string if the specified locale is not supported by the device
- does not re-initialize the widgets that have already loaded the i18n content. For example, assume that an application has 2 forms frmA and frmB.
- frmA is the startup form and loads the content using i18n.getlocalizedstring API. The current locale for the device is en_US and English text is populated on the form.
- onclick event of the button on this form invokes i18n.setcurrentlocale("fr_FR")
- Invoking this API at this stage will not cause the widgets to reload the data for frmA widgets from fr_FR resource bundle.
Platform Availability
- Android
Every application that has support for internationalization needs a locale to be set as a default locale. This API allows you to set the specified locale as the default locale for the application. You can also set the default locale from the IDE. However, this API allows you to perform that task programmatically.
Syntax
kony.i18n.setDefaultLocale(locale);
Input Parameters
locale [String] - Mandatory
Specifies the locale that needs to be set as default locale for the application
Return Values
None
Error Codes
- 100 - if the locale is not supported by device
- 101 - if the locale is supported by device but not by the application
Implementation Details
This API is invoked in the background when the code is generated for an application to set the default locale.
Platform Availability
Available on all platforms.