CmsNlsOperations View code

A singleton class to provide simple, generic mechanism for dealing with languages encodings, and locales. This class does not handle translation strings.

author

Robert Campbell

since 1.11
package

CMS

license

GPL

Methods

get_installed_languages() : array

Get an array of all languages that are known (installed). Udes the NLS files to handle this

static

Response

array

Array of language names

get_language_info(string $lang) : \CmsNls

Get language info about a particular language.

static

Arguments

string $lang

language name.

Response

\CmsNls

object repesenting the named language. or null.

get_current_language() : string

Get the current language.

static

If not explicitly set this method will try to detect the current language. different detection mechanisms are used for admin requests vs. frontend requests. if no match could be found in any way, en_US is returned.

Response

string

Language name.

get_default_language() : string

Get a default language.

static

This method will behave differently for admin or frontend requests.

For admin requests first the preference is checked. Secondly, an attempt is made to find a language understood by the browser that is compatible with what is avaialable. If no match can be found, en_US is assumed.

For frontend requests if a language detector has been set into this object it will be called to attempt to find a language. If that fails, then the frontend language preference is used. Thirdly, if no match is found en_US is assumed.

Response

string

get_frontend_language() : string

Use detection mechanisms to find a suitable frontend language.

static

the language returned must be available as specified by the available NLS Files.

Response

string

language name.

get_admin_language() : string

Use detection mechanisms to find a suitable language for an admin request.

static

The language returned must be an available language as specified by the available NLS Files. If no suitable language can be detected this function will return en_US

Response

string

The language name

detect_browser_language() : string

Cross reference the browser preferred language with those that are available (via NLS Files). To find the first suitable language.

static

Response

string

First suitable lang string. or nothing.

get_browser_languages() : array

Return the list of languages understood by the current browser (if any).

static

Response

array

of Strings representing the languages the browser supports.

get_encoding() : \string.

Return the currently active encoding.

static

If an encoding has not been explicitly set, the default_encoding value from the config file will be used If that value is empty, the encoding associated with the current language will be used. If no suitable encoding can be found, UTF-8 will be assumed.

Response

\string.

set_encoding(mixed $str) 

Set the current encoding

static

Arguments

mixed $str

The encoding (comma separated encodings is acceptable.

set_locale() 

Set the locale for the current language.

static

if language has not been set... does nothing. will use the locale from the nls information for the current locale if config entry is set... it will be used, but subsequent calls to this method will do nothing.

set_language_detector(\CmsLanguageDetector &$obj) 

Used to allow third party modules to override the language detection mechanism for frontend requests.

static

The module can provide an object derived from CmsLanguageDetector to this method.

i.e: CmsNlsOperations::set_language_detector(myLanguageDetector)

Note, this module must return a language for which there is an available NLS file.

Arguments

find_nls_match(string $str) : \hash

Find a match for a specific language This method will try to find the NLS information closest to the language specified.

static

Arguments

string $str

An approximate language specification (an alias matchis done if possible).

Response

\hash

containing NLS information.