Localization

Wrapper around locales and gettext. This class is used internally by Artaengine.
Source
Localization.php
Implements
ILocalization
Depends on
Arta
Since
1.1.0

Static Properties

started = false

Localization::$started = false

gettext has been started or not.

Static Methods

detectLocale

string Localization::detectLocale(array allowedlocales=null, string default='en_US')

Tries to detect and return client locale.

Arguments

    allowedlocales=null (array)
    Array of available locales, detected locale must be in this array
    default='en_US' (string)
    Default locale to be returned when failed to detect

Returns

string
Guessed locale

getDateFormat

string Localization::getDateFormat(string lang=null)

Get the date format set for the lang selected by the user or the lang passed to this method. If format is not defined in the app config then the default format will be returned.

Arguments

    lang=null (string)
    The lang to get date format for, langs and date formats are defined in the app configs null=use the lang selected by the current user

Returns

string
date format e.g. 'Y/m/d'

getHttpAcceptCharset

array Localization::getHttpAcceptCharset()

Returns the "Accept-Charset" header value as an array [CHARSET,] sorted by q

Returns

array
[CHARSET,]

getHttpAcceptLanguage

array Localization::getHttpAcceptLanguage()

Returns the "Accept-Language" header value as an array [LOCALE,] sorted by q

Returns

array
[LOCALE,]

now

string Localization::now(string timeFormat=H:i:s, string zone=null)

Get current time. The timezone is defined in app config under section 'arta' with key 'timezone' if not set it will be 'UTC'. The date format will be the format set to the lang selected by the user, if the lang to date format is not defined in the app configs then the default date format will be used.

Since
Artaengine 1.4.0

Arguments

    timeFormat=H:i:s (string)
    Time format that will be added to the date format
    zone=null (string)
    Time zone, null=default application time zone or 'UTC'

Returns

string
Current date-time

setupGettext

bool Localization::setupGettext()

Starts gettext, configs are fetched from application configuration i18n key. This method will be called on demand or on requests startup by Artaengine. This method will:
1- Find lang/locale: get > post > cookie > session > detect > default > en
2- Set constants LANG and LOCALE
3- Arta::$globals[\'locales\'] = [lang:locale,]
4- $_COOKIE[$key] = LANG
5- only if session has been started $_SESSION[$key] = LANG

Returns

bool
true=gettext is started

start

void Localization::start(array configs)

Defines T() for on demand gettext translation. If in the configs "startup"=true then gettext will be started up immidiately. To use gettext on demand set "startup"=false and the first call as "$translated = T('to translate')" will start gettext.

Arguments

    configs (array)
    i18n configs in an Artaengine app this configs are defined in the app configs ini file or array under the "[i18n]" section
    {
        bool   startup : false
            false=setup and start gettext on demand when function T(string)
            is called true=setup and start gettext after calling "start()".
            if this is set in the app config array or ini file then Artaengine
            will setup and start gettext on app startup,
        string key : lang
            name of the GET/POST/COOKIE/SESSION key which may contain the
            lang key which is selected by the user e.g. lang=en,
        string domain  : application-name Gettext domain setting,
        string locales : APP_DIR/_locales Gettext translation directory,
        string codeset : utf8 Locale code-set. e.g. en_US.utf8,
        string default : en Default lang if no lang is selected,
        bool   detect  : false
            true=use Accept-Language to detect client's lang and locale,
        string lang-key : locale-name
            any langs/locales available in the app must be defined as a
            lang-key: locale-name in the settings.
            e.g. en : en_US, it : it_IT.
            lang-key is an optional string to reference the locale.
            the locale will be set to this key in the request arrays also to
            change the locale lang-key should be set to the
            key value(the config),
    }
    

Returns

void