Locale methods
convertTimestamp( timestamp, toTimeZone, fromTimeZone )
Converts a given timestamp from one timezone to another.
timestampThe timestamp to convert. Expected to be in the givenfromTimezone.toTimeZoneThe desired timezone, one of the PHP constants as specified in http://php.net/manual/en/timezones.php. If none specified, the current Locale timezone is used.fromTimeZoneThe timezone on which the giventimestampis considered to be in. If not specified the default cherrycake timezone is used, as set in Engine::init
Returns: The converted timestamp, or false if it couldn't be converted.
formatCurrency( amount, setup )
Formats the given amount as a currency.
amountsetupAn optional hash array with setup options, with the following possible keys:currencyThe currency to format the given amount to. One of the availableCURRENCY_?. If not specified, the current Locale setting is used.
Returns: The formatted amount.
formatDate( dateTimestamp, setup )
Formats the given date.
dateTimestampThe timestamp to use, in UNIX timestamp format. The hours, minutes and seconds are considered irrelevant.setupAn optional hash array with setup options, just like the Locale::formatTimestamp method.
Returns: The formatted date.
formatNumber( number, setup )
Formats the given number.
numbersetupAn optional hash array with options, with the following possible keys:decimalsThe number of decimals to show. Default:0decimalMarkThe decimal mark to use, either DECIMAL_MARK_POINT or DECIMAL_MARK_COMMA. Defaults to the current locale setting.isSeparateThousandsWhether to separate thousands or not. Default:falsemultiplierA multiplier, or false if no multiplier should be applied. Default:false
Returns: The formatted number.
formatTimestamp( timestamp, setup )
Formats the given date/time according to current locale settings.
timestampThe timestamp to use, in UNIX timestamp format. Considered to be in the engine's default timezone configured in Engine::init, except if thefromTimeZoneis given viasetup.setupA hash array of setup options with the following possible keys:fromTimezoneConsiders the given timestamp to be in this timezone. If not specified, the timestamp is considered to be in the current Locale timestamp. Default:false.toTimezoneConverts the given timestamp to this timezone. If not specified, the given timestamp is converted to the current Locale timestamp except if thefromTimeZonesetup key has been set tofalse. Default:false.languageIf specified, this language will be used instead of the detected one. One of the availableLANGUAGE_?.styleThe formatting style, one of the availableTIMESTAMP_FORMAT_?constants.isShortYearWhether to abbreviate the year whenever possible. For example:17instead of2017.Default:trueisDayWhether to include the day. Default:trueisHoursWhether to include hours and minutes. Default:falsehoursFormatThe format of the hours. One of the availableHOURS_FORMAT_?. Default:HOURS_FORMAT_24isSecondsWhether to include seconds. Default:falseisAvoidYearIfCurrentWhether to avoid the year if it's the current one. Default:falseisBriefWhether to use a brief formatting whenever possible. Default: false.formatIf specified this format as used in the date PHP function is used instead of internal formatting. Default:false
Returns: The formatted timestamp.
getLanguageCode( language )
Gets the code of a language.
languageThe language, one of the availableLANGUAGE_?constants.
Returns: The language code, or false if the specified language is not configured.
getLanguageName( language, setup )
Gets the name of a language.
languageThe language, one of the availableLANGUAGE_?constants.setupAn optional hash array of setup options, with the following possible keys:forceLanguageUse this language instead of the passed inlanguage
Returns: The language name, false if the specified language is not configured.
getMainDomain( localeName )
Gets the main domain name for the current locale, or for the specified locale
localeNameThe name of the locale for which to get the main domain
Returns: The main domain for the specified locale, or for the current locale if no locale specified. false if the locale was not found.
getText( code, setup )
Gets a text from the multilingual texts database.
codeThe code of the text. Can also be specified in the<category code>/<text code>syntax to differentiate texts stored with the same code in different categories.setupAn optional hash array of setup options, with the following possible keys:variablesA hash array of the variables that must be replaced taking the text as a pattern. Every occurrence of{<key>}will be replaced with the matching value, where the value can be a string, or a hash array of values for different languages, where each key is one of the availableLANGUAGE_?constants.forceLanguageForce the retrieval of the text on this language. If not specified, the detected language is used.forceTextCacheTtlUse this TTL for the text cache instead of the module configuration variabletextCacheDefaultTtl.isPurifyVariablesWhether to purify values from specified variables for security purposes or not. Defaults totrue.
Returns: The text.
setLocale( localeName )
Sets the locale to use
localeNameThe name of the locale to use, as specified in theavailableLocalesconfig key.
Returns: true if the locale could be set, false if the locale wasn't configured in the availableLocales config key.
Last updated
Was this helpful?