CMS Made Simple API

CmsNlsOperations
in package

FinalYes

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

Tags
author

Robert Campbell

since
1.11
license

GPL

Table of Contents

Methods

detect_browser_language()  : string
Cross reference the browser preferred language with those that are available (via NLS Files). To find the first suitable language.
get_browser_languages()  : array<string|int, mixed>
Return the list of languages understood by the current browser (if any).
get_current_language()  : string
Get the current language.
get_default_language()  : string
Get a default language.
get_encoding()  : mixed
Return the currently active encoding.
get_installed_languages()  : array<string|int, mixed>
Get an array of all languages that are known (installed). Udes the NLS files to handle this
get_language_info()  : CmsNls
Get language info about a particular language.
set_encoding()  : mixed
Set the current encoding
set_language_detector()  : mixed
Used to allow third party modules to override the language detection mechanism for frontend requests.
find_nls_match()  : hash
Find a match for a specific language This method will try to find the NLS information closest to the language specified.
get_admin_language()  : string
Use detection mechanisms to find a suitable language for an admin request.
get_frontend_language()  : string
Use detection mechanisms to find a suitable frontend language.
set_locale()  : mixed
Set the locale for the current language.

Methods

detect_browser_language()

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

public static detect_browser_language() : string
Return values
string

First suitable lang string. or nothing.

get_browser_languages()

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

public static get_browser_languages() : array<string|int, mixed>
Return values
array<string|int, mixed>

of Strings representing the languages the browser supports.

get_current_language()

Get the current language.

public static get_current_language() : string

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.

Return values
string

Language name.

get_default_language()

Get a default language.

public static get_default_language() : string

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.

Tags
see
set_language_detector
Return values
string

get_encoding()

Return the currently active encoding.

public static get_encoding() : mixed

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.

Tags
@return

string.

get_installed_languages()

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

public static get_installed_languages() : array<string|int, mixed>
Return values
array<string|int, mixed>

Array of language names

get_language_info()

Get language info about a particular language.

public static get_language_info(string $lang) : CmsNls
Parameters
$lang : string

language name.

Return values
CmsNls

object repesenting the named language. or null.

set_encoding()

Set the current encoding

public static set_encoding(mixed $str) : mixed
Parameters
$str : mixed

The encoding (comma separated encodings is acceptable.

set_language_detector()

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

public static set_language_detector(CmsLanguageDetector &$obj) : mixed

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.

Parameters
$obj : CmsLanguageDetector

find_nls_match()

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

protected static find_nls_match(string $str) : hash
Parameters
$str : string

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

Return values
hash

containing NLS information.

get_admin_language()

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

protected static get_admin_language() : string

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

Return values
string

The language name

get_frontend_language()

Use detection mechanisms to find a suitable frontend language.

protected static get_frontend_language() : string

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

Return values
string

language name.

set_locale()

Set the locale for the current language.

protected static set_locale() : mixed

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.


        
On this page

Search results