TTi18n
in package
Table of Contents
- $country : mixed
- $currency_formatter : mixed
- $DEFAULT_NUMBER_FORMAT_PATTERN : mixed
- $is_default_locale : mixed
- $language : mixed
- $locale : mixed
- $master_locale : mixed
- $normalized_locale : mixed
- $number_formatter : mixed
- chooseBestLocale() : string|bool
- Determines the most appropriate locale, based on user metadata including the user's saved locale preference (if any), the user's browser lang pref, and the application's default locale. It also allows an override via setting URL param 'ttlang' to a valid locale.
- convertNoBreakSpace() : array<string|int, mixed>|string|array<string|int, string>
- Converts unicode no-break space into a regular ascii space so we don't have to encode PDFs as UTF-8 just for a space.
- detectUTF8() : bool
- formatCurrency() : mixed|string
- formatNumber() : string
- Format a number in the manner consistent with the current locale -In the first case, only the number is provided. this formats to the default pattern for the locale.
- generateLocale() : array<string|int, mixed>|mixed
- getAfterDecimal() : int
- getBrowserLanguage() : array<string|int, mixed>
- getCountry() : string
- getCountryFromLocale() : bool
- getCurrencyArray() : mixed
- getCurrencySymbol() : mixed|string
- getDecimalSymbol() : string
- Get the current locale's decimal symbol
- getLanguage() : string
- getLanguageArray() : array<string|int, mixed>
- getLanguageFromLocale() : bool|string
- getLocale() : null
- getLocaleArrayAsString() : string
- getLocaleCookie() : bool
- getNormalizedLocale() : string|null
- getPDFDefaultFont() : string
- Returns PDF font appropriate for language.
- getSupportedLanguagesArray() : array<string|int, string>
- Return array of supported languages.
- getText() : string
- getTextStringArgs() : string
- getThousandsSymbol() : string
- Get the current locale's thousands separator symbol
- parseFloat() : int|float|string
- Parses a locale specific string that represents a float (ie: -46,1234 or -46.1234) and converts it to a float that PHP will recognize for math functions like number_format()/round, etc... This strips out all non-float characters as well, so no need to call Validator->stripNonFloat() before or after this. In fact we *can't* call Validator->stripNonFloat() before this as it will break parsing values from other locales with commas in them.
- setCountry() : bool
- setGetTextLocale() : bool
- setLanguage() : bool
- setLocale() : bool
- setLocaleCookie() : bool
- setMasterLocale() : bool
- stripUTF8() : bool|string
- strtolower() : string
- strtoupper() : string
- tryLocale() : bool|string
- ucfirst() : string
- _normalizeLocale() : string
- Returns a fully normalized locale string, or the original string if no match was found.
Properties
$country
private
static mixed
$country
= 'US'
$currency_formatter
private
static mixed
$currency_formatter
= \false
$DEFAULT_NUMBER_FORMAT_PATTERN
private
static mixed
$DEFAULT_NUMBER_FORMAT_PATTERN
= '#,##0.##'
$is_default_locale
private
static mixed
$is_default_locale
= \true
$language
private
static mixed
$language
= 'en'
$locale
private
static mixed
$locale
= \null
$master_locale
private
static mixed
$master_locale
= \null
$normalized_locale
private
static mixed
$normalized_locale
= \null
$number_formatter
private
static mixed
$number_formatter
= \false
Methods
chooseBestLocale()
Determines the most appropriate locale, based on user metadata including the user's saved locale preference (if any), the user's browser lang pref, and the application's default locale. It also allows an override via setting URL param 'ttlang' to a valid locale.
public
static chooseBestLocale([string|array<string|int, mixed> $user_locale_pref = null ]) : string|bool
Returns the best locale, or false if unable to find and set a locale.
Parameters
- $user_locale_pref : string|array<string|int, mixed> = null
Tags
Return values
string|bool —convertNoBreakSpace()
Converts unicode no-break space into a regular ascii space so we don't have to encode PDFs as UTF-8 just for a space.
public
static convertNoBreakSpace( $string) : array<string|int, mixed>|string|array<string|int, string>
Parameters
Return values
array<string|int, mixed>|string|array<string|int, string> —detectUTF8()
public
static detectUTF8( $string) : bool
Parameters
Return values
bool —formatCurrency()
public
static formatCurrency(int|float|string $amount[, null $currency_code = null ], int $show_code) : mixed|string
Parameters
- $amount : int|float|string
- $currency_code : null = null
- $show_code : int
-
0 = No, 1 = Left, 2 = Right
Return values
mixed|string —formatNumber()
Format a number in the manner consistent with the current locale -In the first case, only the number is provided. this formats to the default pattern for the locale.
public
static formatNumber(decimal|string $number[, bool $auto_format_decimals = false ][, int $min_decimals = 2 ][, int $max_decimals = 4 ]) : string
-In the second case, $auto_format_decimals is provided as TRUE with both $min_decimals and $max_decimals set. this defines the number of decimals.
Parameters
- $number : decimal|string
- $auto_format_decimals : bool = false
- $min_decimals : int = 2
- $max_decimals : int = 4
Return values
string —[formatted number]
generateLocale()
public
static generateLocale([null $locale_arg = null ]) : array<string|int, mixed>|mixed
Parameters
- $locale_arg : null = null
Return values
array<string|int, mixed>|mixed —getAfterDecimal()
public
static getAfterDecimal( $number, int $min_decimals[, int $max_decimals = 16 ]) : int
Parameters
Return values
int —getBrowserLanguage()
public
static getBrowserLanguage() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —getCountry()
public
static getCountry() : string
Return values
string —getCountryFromLocale()
public
static getCountryFromLocale([null $locale = null ]) : bool
Parameters
- $locale : null = null
Return values
bool —getCurrencyArray()
public
static getCurrencyArray() : mixed
Return values
mixed —getCurrencySymbol()
public
static getCurrencySymbol( $iso_code) : mixed|string
Parameters
Return values
mixed|string —getDecimalSymbol()
Get the current locale's decimal symbol
public
static getDecimalSymbol() : string
Return values
string —getLanguage()
public
static getLanguage() : string
Return values
string —getLanguageArray()
public
static getLanguageArray() : array<string|int, mixed>
Return values
array<string|int, mixed> —getLanguageFromLocale()
public
static getLanguageFromLocale([null $locale = null ]) : bool|string
Parameters
- $locale : null = null
Return values
bool|string —getLocale()
public
static getLocale() : null
Return values
null —getLocaleArrayAsString()
public
static getLocaleArrayAsString( $locale_arr) : string
Parameters
Return values
string —getLocaleCookie()
public
static getLocaleCookie() : bool
Return values
bool —getNormalizedLocale()
public
static getNormalizedLocale() : string|null
Return values
string|null —getPDFDefaultFont()
Returns PDF font appropriate for language.
public
static getPDFDefaultFont([null $language = null ][, bool $encoding = false ]) : string
Parameters
- $language : null = null
- $encoding : bool = false
Return values
string —getSupportedLanguagesArray()
Return array of supported languages.
public
static getSupportedLanguagesArray() : array<string|int, string>
Return values
array<string|int, string> —getText()
public
static getText( $str[, bool $args = false ]) : string
Parameters
Return values
string —getTextStringArgs()
public
static getTextStringArgs( $str, $args) : string
Parameters
Return values
string —getThousandsSymbol()
Get the current locale's thousands separator symbol
public
static getThousandsSymbol() : string
Return values
string —parseFloat()
Parses a locale specific string that represents a float (ie: -46,1234 or -46.1234) and converts it to a float that PHP will recognize for math functions like number_format()/round, etc... This strips out all non-float characters as well, so no need to call Validator->stripNonFloat() before or after this. In fact we *can't* call Validator->stripNonFloat() before this as it will break parsing values from other locales with commas in them.
public
static parseFloat( $value[, int $precision = 2 ]) : int|float|string
Parameters
Return values
int|float|string —setCountry()
public
static setCountry( $country) : bool
Parameters
Return values
bool —setGetTextLocale()
public
static setGetTextLocale( $locale) : bool
Parameters
Return values
bool —setLanguage()
public
static setLanguage( $language) : bool
Parameters
Return values
bool —setLocale()
public
static setLocale([null $locale_arg = null ][, int $category = LC_ALL ][, bool $force = false ]) : bool
Parameters
- $locale_arg : null = null
- $category : int = LC_ALL
- $force : bool = false
Return values
bool —setLocaleCookie()
public
static setLocaleCookie([null $locale = null ]) : bool
Parameters
- $locale : null = null
Return values
bool —setMasterLocale()
public
static setMasterLocale() : bool
Return values
bool —stripUTF8()
public
static stripUTF8( $str) : bool|string
Parameters
Return values
bool|string —strtolower()
public
static strtolower( $str) : string
Parameters
Return values
string —strtoupper()
public
static strtoupper( $str) : string
Parameters
Return values
string —tryLocale()
public
static tryLocale( $locale) : bool|string
Parameters
Return values
bool|string —ucfirst()
public
static ucfirst( $str) : string
Parameters
Return values
string —_normalizeLocale()
Returns a fully normalized locale string, or the original string if no match was found.
protected
static _normalizeLocale(string $locale) : string
Parameters
- $locale : string
-
a locale string of the form 'es', or 'es_CR'. Both will be converted to 'es_ES'