ILocalization

Interface for wrapper class around locales and gettext. This interface is used internally by Artaengine.
Source
ILocalization.php
Implementations
Localization

Static Methods

detectLocale

string ILocalization::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

getHttpAcceptCharset

array ILocalization::getHttpAcceptCharset()

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

Returns

array
[CHARSET,]

getHttpAcceptLanguage

array ILocalization::getHttpAcceptLanguage()

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

Returns

array
[LOCALE,]

setupGettext

bool ILocalization::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 ILocalization::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