class CRM_Core_I18n

Constants

NONE

Constants for communication preferences.

AUTO

Constants for communication preferences.

Properties

static callable|null $SQL_ESCAPER

Methods

static string
escapeSql(string $text)

Encode a string for use in SQL.

__construct(string $locale)

A locale-based constructor that shouldn't be called from outside of this class (use singleton() instead).

bool
isNative()

Returns whether gettext is running natively or using PHP-Gettext.

setNativeGettextLocale(string $locale)

Set native locale for getText.

setPhpGettextLocale(string $locale)

Set getText locale.

static array
languages(bool $justEnabled = FALSE)

Return languages available in this instance of CiviCRM.

static array|string
uiLanguages($justCodes = FALSE)

Return the available UI languages

string
strarg(string $str)

Replace arguments in a string with their values. Arguments are represented by % followed by their number.

static string
getResourceDir()

Get the directory for l10n resources.

string
crm_translate(string $text, array $params = [])

Smarty block function, provides gettext support for smarty.

string
crm_translate_raw(string $text, string|null $domain, int|null $count, string $plural, string $context)

Lookup the raw translation of a string (without any extra escaping or interpolation).

string
translate(string $string)

Translate a string to the current locale.

localizeArray(array $array, array $params = [])

Localize (destructively) array values.

localizeTitles(array $array)

Localize (destructively) array elements with keys of 'title'.

Bool
setGettextDomain($key)

Binds a gettext domain, wrapper over bindtextdomain().

static Bool
isMultilingual()

Is the CiviCRM in multilingual mode.

static Bool
isLanguageRTL($language)

Is the language written "right-to-left"?

setLocale($locale)

Change the processing language without changing the current user language

static CRM_Core_I18n
singleton()

Static instance provider - return the instance for the current locale.

static string
setLcTime()

Set the LC_TIME locale if it's not set already (for a given language choice).

static string
getContactDefaultLanguage()

Get the default language for contacts where no language is provided.

static string
getLocale()

Get the current locale

Details

at line 62
static protected string escapeSql(string $text)

Encode a string for use in SQL.

Parameters

string $text

Return Value

string

at line 105
CRM_Core_I18n __construct(string $locale)

A locale-based constructor that shouldn't be called from outside of this class (use singleton() instead).

Parameters

string $locale the base of this certain object's existence.

Return Value

CRM_Core_I18n

at line 127
bool isNative()

Returns whether gettext is running natively or using PHP-Gettext.

Return Value

bool True if gettext is native

at line 136
protected setNativeGettextLocale(string $locale)

Set native locale for getText.

Parameters

string $locale

at line 160
protected setPhpGettextLocale(string $locale)

Set getText locale.

Parameters

string $locale

at line 190
static array languages(bool $justEnabled = FALSE)

Return languages available in this instance of CiviCRM.

Parameters

bool $justEnabled whether to return all languages or just the enabled ones.

Return Value

array Array of code/language name mappings

at line 252
static array|string uiLanguages($justCodes = FALSE)

Return the available UI languages

Parameters

$justCodes

Return Value

array|string array(string languageCode => string languageName) if !$justCodes

at line 278
string strarg(string $str)

Replace arguments in a string with their values. Arguments are represented by % followed by their number.

Parameters

string $str source string.

Return Value

string modified string

at line 300
static string getResourceDir()

Get the directory for l10n resources.

Return Value

string

at line 334
string crm_translate(string $text, array $params = [])

Smarty block function, provides gettext support for smarty.

The block content is the text that should be translated.

Any parameter that is sent to the function will be represented as %n in the translation text, where n is 1 for the first parameter. The following parameters are reserved: - escape - sets escape mode: - 'html' for HTML escaping, this is the default. - 'js' for javascript escaping. - 'no'/'off'/0 - turns off escaping - plural - The plural version of the text (2nd parameter of ngettext()) - count - The item count for plural mode (3rd parameter of ngettext()) - context - gettext context of that string (for homonym handling)

Parameters

string $text the original string.
array $params The params of the translation (if any). - domain: string|array a list of translation domains to search (in order) - context: string - skip_translation: flag (do only escape/replacement, skip the actual translation)

Return Value

string the translated string

at line 432
protected string crm_translate_raw(string $text, string|null $domain, int|null $count, string $plural, string $context)

Lookup the raw translation of a string (without any extra escaping or interpolation).

Parameters

string $text
string|null $domain
int|null $count
string $plural
string $context

Return Value

string

at line 522
string translate(string $string)

Translate a string to the current locale.

Parameters

string $string this string should be translated.

Return Value

string the translated string

at line 534
localizeArray(array $array, array $params = [])

Localize (destructively) array values.

Parameters

array $array the array for localization (in place).
array $params an array of additional parameters.

at line 557
localizeTitles(array $array)

Localize (destructively) array elements with keys of 'title'.

Parameters

array $array the array for localization (in place).

at line 578
Bool setGettextDomain($key)

Binds a gettext domain, wrapper over bindtextdomain().

Parameters

$key Key of the extension (can be 'civicrm', or 'org.example.foo').

Return Value

Bool True if the domain was changed for an extension.

at line 632
static Bool isMultilingual()

Is the CiviCRM in multilingual mode.

Return Value

Bool True if CiviCRM is in multilingual mode.

at line 647
static Bool isLanguageRTL($language)

Is the language written "right-to-left"?

Parameters

$language Language (for example 'en_US', or 'fr_CA').

Return Value

Bool True if it is an RTL language.

at line 661
setLocale($locale)

Change the processing language without changing the current user language

Parameters

$locale Locale (for example 'en_US', or 'fr_CA'). True if the domain was changed for an extension.

at line 692
static CRM_Core_I18n singleton()

Static instance provider - return the instance for the current locale.

Return Value

CRM_Core_I18n

at line 710
static string setLcTime()

Set the LC_TIME locale if it's not set already (for a given language choice).

Return Value

string the final LC_TIME that got set

at line 732
static string getContactDefaultLanguage()

Get the default language for contacts where no language is provided.

Note that NULL is a valid option so be careful with checking for empty etc.

NULL would mean 'we don't know & we don't want to hazard a guess'.

Return Value

string

at line 755
static string getLocale()

Get the current locale

Return Value

string