caplin.i18n
package that is responsible for translating localization tokens in the
form of @{key.name}
into translated text.
Attributes | Name and Description |
---|---|
|
caplin.i18n.Translator( messagesMap)
Do not instantiate this class directly. |
Attributes | Name and Description |
---|---|
|
String
convertXMLEntityChars(String text)
Converts XML reserved characters (<,>,',',&) into XML entity references. |
|
String
formatDate(Date date, String format)
Formats a JavaScript date object according to the locale date format string or another passed in date format string. |
|
String
formatNumber(String|int num, String thousandsSeparator)
Formats the number appropriately for the locale. |
|
String
formatTime(String|int time)
Formats the time appropriately for the locale. |
|
String
getDateFormat()
Returns the current date format string for use in displaying the current date format or for other components that require it to format dates. |
|
String
getLocale()
Returns the locale that the current site has been loaded in. |
|
String
getMessage(String token, Map templateTokens)
The |
|
String
getShortDateFormat()
Returns the shorter version of the current date format string for use in displaying the current date format or for other components that require it to format dates. |
<static>
|
caplin.i18n.Translator
getTranslator()
Returns an instance of the |
|
Number
parseNumber(Variant sNumber, String thousandsSeparator)
Parses the number appropriately for the locale, by removing the ThousandsSeperators and decimal points. |
|
void
setLocalizationPreferences(Map localizationPreferences)
Sets localization preferences for the |
|
String
stripNonNumericCharacters(String value)
Strips non numeric characters from the specified string. |
|
boolean
tokenExists(String text)
Returns whether the current locale contains a given localization token. |
|
String
translate(String text, String type)
Translate is used to convert raw localization tokens in the form |
►
caplin.i18n.Translator( messagesMap)
Do not instantiate this class directly. To access the localization token translator use the global
ct.i18n(token, args)
function, which maps to the getMessage()
function.
messagesMap |
►
String
convertXMLEntityChars(String text)
Converts XML reserved characters (<,>,',',&) into XML entity references.
String | text | The string within which to replace localization tokens. |
►
String
formatDate(Date date, String format)
Formats a JavaScript date object according to the locale date format string or another passed in date format string.
If no date format string is supplied, this function will default to the date format string referenced by the
localization property ct.i18n.date.format
.
Try using the following:
var oTranslator = caplin.i18n.Translator.getTranslator(); oTranslator.formatDate(myDateObject);
Note that this method will also translate any month names (including abbreviated month names) in the date string to the local equivalents. In order for this translation to work correctly, two sets of localization properties need to be set-up.
For translation of long month names define localization properties of the form: date.month.january=January
For translation of abbreviated month names define localization properties of the form: date.month.short.january=Jan
Date | date | A Date object to output as a formatted string. |
String | format | (optional) The date format to use. The date formats supported are the same as those used by the Moment.js Date object. Refer to the Moment.js API documentation for further details. |
►
String
formatNumber(String|int num, String thousandsSeparator)
Formats the number appropriately for the locale.
By specifying a number grouping separator character (',' for example) as the value of the localization property
ct.i18n.number.grouping.separator
, a number such as '1000000' will be formatted as '1,000,000'.
Try using the following:
var oTranslator = caplin.i18n.Translator.getTranslator(); oTranslator.formatNumber(1000000);
String|int | num | A number or a string representing the number. |
String | thousandsSeparator | (optional) A string representing thousands separator. |
num
.
►
String
formatTime(String|int time)
Formats the time appropriately for the locale.
By specifying a time separator character (':' for example) as the value of the localization property
ct.i18n.time.format.separator
, a time such as '102001' will be formatted as '10:20:01'.
Try using the following:
var oTranslator = caplin.i18n.Translator.getTranslator(); oTranslator.formatTime(102001);
String|int | time | An integer or string representing the time. |
time
.
►
String
getDateFormat()
Returns the current date format string for use in displaying the current date format or for other components that require it to format dates.
The string is either the default for the locale or if the user has set a preference, then that is returned instead.
►
String
getLocale()
Returns the locale that the current site has been loaded in.
►
String
getMessage(String token, Map templateTokens)
The getMessage
method replaces a token with it's translation.
Additionally, you can supply extra template arguments that the particular translation might need. For example, a given translations may be ${dialog.message.amountWarning} = 'you have [template.key.amount] dollars left in account [template.key.account]'.
To get the fully translated message 'you have 43234 dollars left in account testAccount', you would call:
ct.i18n('dialog.message.amountWarning', {
'template.key.amount': '43234',
'template.key.account': 'testAccount'
});
String | token | The token to be translated. |
Map | templateTokens | (optional) The template arguments a translation may require. |
►
String
getShortDateFormat()
Returns the shorter version of the current date format string for use in displaying the current date format or for other components that require it to format dates.
The string is either the default for the locale or if the user has set a preference then that is returned instead.
►
<static>
caplin.i18n.Translator
getTranslator()
Returns an instance of the Translator
.
Translator
for i18n translations for use within this instance of the application.
►
Number
parseNumber(Variant sNumber, String thousandsSeparator)
Parses the number appropriately for the locale, by removing the ThousandsSeperators and decimal points.
By specifying a number grouping separator character (',' for example) as the value of the localization property
ct.i18n.number.grouping.separator
, a number such as '1,000,000' will be parsed as '1000000'.
Try using the following:
var oTranslator = caplin.i18n.Translator.getTranslator(); oTranslator.parseNumber(1,000,000.00);
Variant | sNumber | A string representing the number. |
String | thousandsSeparator | (optional) A string representing thousands separator. |
►
void
setLocalizationPreferences(Map localizationPreferences)
Sets localization preferences for the Translator
.
Map | localizationPreferences | A map containing the localization preferences. |
►
String
stripNonNumericCharacters(String value)
Strips non numeric characters from the specified string.
String | value | The string to strip the non numeric values from. |
►
boolean
tokenExists(String text)
Returns whether the current locale contains a given localization token.
Usage: caplin.i18n.Translator.getTranslator().tokenExists('ct.core.field.start.date');
String | text | The token name |
true
if the localization token exists in the current locale's translation set,
otherwise false
.
►
String
translate(String text, String type)
Translate is used to convert raw localization tokens in the form @{key.name}
into translated text.
By default this method also converts reserved XML characters (<,>,",',&) into XML entity references (> into > etc). If you require raw text translation without the XML entity reference conversion, pass a type of 'text' as an argument to this method.
String | text | The string within which to replace localization tokens. |
String | type | The type of text to translate (defaults to 'xml', pass 'text' for translation without XML entity reference conversion). |