Cherrycake
ExamplesGithub
version 2.x alpha
version 2.x alpha
  • Introduction
  • Status
  • Changelog
  • Migration
  • Architecture
    • Basics
    • Modules
    • Classes
    • Lifecycle
      • Deep lifecycle
    • Performance
    • Security
    • Patterns
      • Files structure
    • Items
    • Server requirements
  • Guide
    • Getting started
      • Skeleton start
      • Docker start
    • Modules guide
    • Classes guide
    • Actions guide
      • Complex actions
      • Variable path components
      • Accept GET or POST parameters
      • Getting the URL of an action
      • Cached actions
      • Brute force attacks
    • Patterns guide
      • Passing variables to a pattern
      • Nested patterns
      • Cached patterns
    • Cache guide
      • Time To Live
      • Using cache
      • Lists
      • Queues
      • Pools
    • Database guide
      • Basic queries
      • Prepared queries
      • Cached queries
      • Cache key naming
      • Removing queries from cache
    • Items guide
      • Item cache
      • Item lists
      • Items custom filters
      • Items custom ordering
      • Mixing filters and ordering
      • Items with relationships
      • Items cache
    • HtmlDocument guide
    • Css and Javascript guide
      • Modules injecting CSS and JavaScript
    • Session guide
    • Login guide
      • Creating a complete login workflow
    • Locale guide
      • Multilingual texts
      • Domain based site localization
    • Log guide
      • Loading Log events from the database
    • Stats guide
      • Stats events with additional dimensions
      • Loading Stats events from the database
    • Janitor guide
      • Janitor tasks configuration files
    • Command line interface
    • Debugging
  • Reference
    • Core modules
      • Actions
        • Actions methods
      • Browser
      • Cache
        • Cache methods
      • Css
        • Css methods
      • Database
      • Email
      • Errors
      • HtmlDocument
        • HtmlDocument methods
      • ItemAdmin
      • Janitor
        • Janitor methods
      • Javascript
        • Javascript methods
      • Locale
        • Locale methods
      • Log
        • Log methods
      • Login
        • Login methods
      • Output
        • Output methods
      • Patterns
        • Patterns methods
      • Security
        • Security methods
      • Session
        • Session methods
      • Stats
        • Stats methods
      • SystemLog
      • TableAdmin
      • Translation
      • Validate
    • Core classes
      • Action
        • Action methods
        • Action properties
      • AjaxResponseJson
      • BasicObject
        • BasicObject methods
      • CacheProvider
        • CacheProvider methods
      • Color
      • DatabaseProvider
        • DatabaseProvider methods
      • DatabaseResult
        • DatabaseResult methods
        • DatabaseResult properties
      • DatabaseRow
      • Engine
        • Engine methods
        • Engine properties
      • Gradient
      • Item
        • Item methods
        • Item properties
      • Items
        • Items methods
        • Items properties
      • Image
      • JanitorTask
        • JanitorTask methods
        • JanitorTask properties
      • LogEvent
        • LogEvent methods
        • LogEvent Properties
      • LogEvents
        • LogEvents methods
      • Module
        • Module methods
        • Module properties
      • Response
      • Request
        • Request methods
      • RequestParameter
        • RequestParameter methods
      • RequestPathComponent
        • RequestPathComponent methods
      • Result
      • StatsEvent
        • StatsEvent properties
      • StatsEvents
        • StatsEvents methods
      • SystemLogEvent
        • SystemLogEvent methods
        • SystemLogEvent properties
      • SystemLogEvents
        • SystemLogEvents methods
  • Code conventions
  • License
  • Extras
Powered by GitBook
On this page
  • convertTimestamp( timestamp, toTimeZone, fromTimeZone )
  • formatCurrency( amount, setup )
  • formatDate( dateTimestamp, setup )
  • formatNumber( number, setup )
  • formatTimestamp( timestamp, setup )
  • getLanguageCode( language )
  • getLanguageName( language, setup )
  • getMainDomain( localeName )
  • getText( code, setup )
  • setLocale( localeName )

Was this helpful?

  1. Reference
  2. Core modules
  3. Locale

Locale methods

PreviousLocaleNextLog

Last updated 4 years ago

Was this helpful?

convertTimestamp( timestamp, toTimeZone, fromTimeZone )

Converts a given timestamp from one timezone to another.

  • timestamp The timestamp to convert. Expected to be in the given fromTimezone.

  • toTimeZone The desired timezone, one of the PHP constants as specified in . If none specified, the current timezone is used.

  • fromTimeZone The timezone on which the given timestamp is considered to be in. If not specified the default cherrycake timezone is used, as set in

Returns: The converted timestamp, or false if it couldn't be converted.

formatCurrency( amount, setup )

Formats the given amount as a currency.

  • amount

  • setup An optional hash array with setup options, with the following possible keys:

    • currency The currency to format the given amount to. One of the available . If not specified, the current setting is used.

Returns: The formatted amount.

formatDate( dateTimestamp, setup )

Formats the given date.

  • dateTimestamp The timestamp to use, in UNIX timestamp format. The hours, minutes and seconds are considered irrelevant.

Returns: The formatted date.

formatNumber( number, setup )

Formats the given number.

  • number

  • setup An optional hash array with options, with the following possible keys:

    • decimals The number of decimals to show. Default: 0

    • decimalMark The decimal mark to use, either DECIMAL_MARK_POINT or DECIMAL_MARK_COMMA. Defaults to the current locale setting.

    • isSeparateThousands Whether to separate thousands or not. Default: false

    • multiplier A 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.

  • setup A hash array of setup options with the following possible keys:

    • isShortYear Whether to abbreviate the year whenever possible. For example: 17 instead of 2017. Default: true

    • isDay Whether to include the day. Default: true

    • isHours Whether to include hours and minutes. Default: false

    • isSeconds Whether to include seconds. Default: false

    • isAvoidYearIfCurrent Whether to avoid the year if it's the current one. Default: false

    • isBrief Whether to use a brief formatting whenever possible. Default: false.

    • format If 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.

Returns: The language code, or false if the specified language is not configured.

getLanguageName( language, setup )

Gets the name of a language.

  • setup An optional hash array of setup options, with the following possible keys:

    • forceLanguage Use this language instead of the passed in language

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

  • localeName The 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.

  • code The 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.

  • setup An optional hash array of setup options, with the following possible keys:

    • forceLanguage Force the retrieval of the text on this language. If not specified, the detected language is used.

    • forceTextCacheTtl Use this TTL for the text cache instead of the module configuration variable textCacheDefaultTtl.

    • isPurifyVariables Whether to purify values from specified variables for security purposes or not. Defaults to true.

Returns: The text.

setLocale( localeName )

Sets the locale to use

setup An optional hash array with setup options, just like the method.

timestamp The timestamp to use, in UNIX timestamp format. Considered to be in the engine's default timezone configured in , except if the fromTimeZone is given via setup.

fromTimezone Considers the given timestamp to be in this timezone. If not specified, the timestamp is considered to be in the current timestamp. Default: false.

toTimezone Converts the given timestamp to this timezone. If not specified, the given timestamp is converted to the current timestamp except if the fromTimeZone setup key has been set to false. Default: false.

language If specified, this language will be used instead of the detected one. One of the available .

style The formatting style, one of the available constants.

hoursFormat The format of the hours. One of the available . Default: HOURS_FORMAT_24

language The language, one of the available constants.

language The language, one of the available constants.

variables A 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 available constants.

localeName The name of the locale to use, as specified in the config key.

Returns: true if the locale could be set, false if the locale wasn't configured in the config key.

Locale
Locale
Locale::formatTimestamp
http://php.net/manual/en/timezones.php
Locale
Locale
LANGUAGE_?
TIMESTAMP_FORMAT_?
HOURS_FORMAT_?
LANGUAGE_?
LANGUAGE_?
LANGUAGE_?
availableLocales
availableLocales
CURRENCY_?
Engine::init
Engine::init