Skip to content

classes_essentials_localization_localization.class

Daniel Spors edited this page Nov 14, 2024 · 5 revisions

Classes in file essentials/localization/localization.class.php

class Localization

Helper class to wrap some tool functions.

convert_countrycode

Converts 2-letter to 3-letter country codes and vice-versa.

Definition: public static function convert_countrycode($country_code)

Returns: bool|string Returns 2-letter if 3-letter was given, or vice-versa, or false if invalid

Parameters:

  • string $country_code country code.

detectCulture

Tries to detect the culture for the remote user.

Definition: public static function detectCulture($detectionOrder=false)

Returns: CultureInfo The detected culture or $CONFIG['localization']['default_culture']

Parameters:

  • array $detectionOrder Array specifying the detection order like this: array(Localization::USE_BROWSER,Localization::USE_IP)

ensureCulture

Ensures a culture to a given code. Calls Localization::getCultureInfo and if that fails Localization::detectCulture to ensure there's a return value.

Definition: public static function ensureCulture($code, $detectionOrder=false)

Returns: CultureInfo The best match culture for $code

Parameters:

getAllTimeZones

Returns a list of all defined Timezones. Wraps DateTimeZone::listIdentifiers

Definition: public static function getAllTimeZones()

Returns: array All Timezone IDs

getBrowserCulture

Detects the browsers culture settings. $_SERVER['HTTP_FORCE_LANGUAGE'] = forced by request (like api calls from client, portal, ...) An override can be given by setting GET['culture'] or COOKIE['culture'], it will be checked only when $checkoverride is true.

Definition: public static function getBrowserCulture($checkoverride=true)

Returns: CultureInfo|bool The detected culture

Parameters:

  • bool $checkoverride Whether to check for given culture

getCultureInfo

Retuns a CultureInfo object.

Definition: public static function getCultureInfo($code)

Returns: CultureInfo CultureInfo object representing the culture or false on error

Parameters:

  • string $code Country code, Language code or culture code

getIPCulture

Tries to match the remote IP to a culture.

Definition: public static function getIPCulture()

Returns: CultureInfo|bool The detected culture or false

getLanguageCulture

Gets a CultureInfo object representing a language.

Definition: public static function getLanguageCulture($language_code)

Returns: CultureInfo The object or false on error

Parameters:

  • string $language_code Lanugage code (DE, EN, ...)

getTimeZone

Returns the timezone by IP. Will fall back to the $CONFIG['localization']['default_timezone'] setting

Definition: public static function getTimeZone($ip=false)

Returns: string Timezone ID

Parameters:

  • string $ip IP to get the timezone for

get_all_regions

Returns all defined regions.

Definition: public static function get_all_regions($only_codes=false)

Returns: array Array of depending on $only_codes only that or complete RegionInfo objects

Parameters:

  • bool $only_codes If true only the codes are returned

get_countrycodeA2ISOfromA3

Returns the A2 ISO3166 country code from a given A3 ISO3166 country code.

Definition: public static function get_countrycodeA2ISOfromA3($country_code)

Returns: string The A2 ISO3166 or false on error

Parameters:

  • string $country_code The country code as A3

get_country_culture

Gets the default culture for a country.

Definition: public static function get_country_culture($country_code)

Returns: CultureInfo|bool The default culture or false on error

Parameters:

  • string $country_code Country code

get_country_names

Gets a list of country names.

Definition: public static function get_country_names($culture_filter=false)

Returns: array Associative array of countrycode=>countryname pairs

Parameters:

  • mixed $culture_filter CultureInfo or code specifying a culture that must be present in a country

get_country_region

Gets the RegionInfo for a country.

Definition: public static function get_country_region($country_code)

Returns: RegionInfo|bool The region info or false on error

Parameters:

  • string $country_code Country code

get_country_states

Returns an array of states for a country (USA only ATM).

Definition: public static function get_country_states($country_code)

Returns: array Associative array of code=>name pairs

Parameters:

  • string $country_code The country code to list states of

get_currency

Returns the currently selected currency.

Definition: public static function get_currency($cultureCode=false, $use_code=false)

Returns: string Currency code|symbol

Parameters:

  • string $cultureCode The culture code for which we need the currency. defaults to current culture

  • bool $use_code true: return currency ISO code, false: return currency symbol

get_currency_codes

Returns a list of all supported currency codes.

Definition: public static function get_currency_codes()

Returns: array List of currency codes

get_currency_culture

Gets a CultureInfo from a currency code.

Definition: public static function get_currency_culture($currency_code)

Returns: CultureInfo The detected culture or false on error

Parameters:

  • string $currency_code Valid currency code(see <get_currency_codes>)

get_currency_culture_codes

Returns a list of cultures the given currency is used in.

Definition: public static function get_currency_culture_codes($currency_code)

Returns: array string[] of currency codes

Parameters:

  • string $currency_code The currency to check

get_language_names

Returns a list of all languages. Note that this method returns the english names of the languages (German, French, ...).

Definition: public static function get_language_names()

Returns: array Associative array of lang_code=>lang_name pairs

localization_default_culture

Returns the default Culture That is set in $CONFIG['localization']['default_culture']

Definition: public static function localization_default_culture()

Returns: string Default culture code

Clone this wiki locally