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( mMessages)
Do not instantiate this class directly. |
Attributes | Name and Description |
---|---|
|
String
convertXMLEntityChars(String sText)
Converts XML reserved characters (<,>,",',&) into XML entity references. |
|
String
formatDate(Date oDate, String sDateFormat)
Formats a JavaScript date object according to the locale date format string or another passed in date format string. |
|
String
formatNumber(Variant vNumber, sThousandsSeparator)
Formats the number appropriately for the locale. |
|
String
formatTime(Variant vTime)
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 sToken, Map mTemplateArgs)
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, sThousandsSeparator)
Parses the number appropriately for the locale, by removing the ThousandsSeperators and decimal points. |
|
void
setLocalizationPreferences(Map mLocalizationPrefs)
Sets localization preferences for the |
|
String
stripNonNumericCharacters(String sValue)
Strings non numeric characters from the specified string. |
|
boolean
tokenExists(String sText)
Returns whether the current locale contains a given localization token. |
|
String
translate(String sText, String sType)
Translate is used to convert raw localization tokens in the form
|
►
caplin.i18n.Translator( mMessages)
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.
mMessages |
►
String
convertXMLEntityChars(String sText)
Converts XML reserved characters (<,>,",',&) into XML entity references.
String | sText | The string within which to replace localization tokens. |
►
String
formatDate(Date oDate, String sDateFormat)
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 | oDate | A Date object to output as a formatted string. |
String | sDateFormat | An optional 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(Variant vNumber, sThousandsSeparator)
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);
Variant | vNumber | A number or a string representing the number. |
sThousandsSeparator |
vNumber
.
►
String
formatTime(Variant vTime)
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);
Variant | vTime | An integer or string representing the time. |
vTime
.
►
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 sToken, Map mTemplateArgs)
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]". You would call
ct.i18n("dialog.message.amountWarning",
{"template.key.amount":"43234", "template.key.account":"testAccount"});
to get the fully translated message "you have 43234 dollars left in account
testAccount"
String | sToken | The token to be translated. |
Map | mTemplateArgs | The *optional* 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, sThousandsSeparator)
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 a string representing the number. |
sThousandsSeparator |
►
void
setLocalizationPreferences(Map mLocalizationPrefs)
Sets localization preferences for the Translator
.
Map | mLocalizationPrefs | A map containing the localization preferences. |
►
String
stripNonNumericCharacters(String sValue)
Strings non numeric characters from the specified string.
String | sValue | the string to strip the non numeric values from. |
►
boolean
tokenExists(String sText)
Returns whether the current locale contains a given localization token.
Usage: caplin.i18n.Translator.getTranslator().tokenExists("ct.core.field.start.date")
String | sText | The token name |
true
if the localization token exists in the current locale's
translation set, otherwise false
.
►
String
translate(String sText, String sType)
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 | sText | The string within which to replace localization tokens. |
String | sType | The type of text to translate (defaults to "xml", pass "text" for translation without XML entity reference conversion). |