class CRM_Core_I18n

Constants

NONE

Constants for communication preferences.

AUTO

Constants for communication preferences.

Methods

__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.

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 = array())

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 = array())

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 74
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 96
bool isNative()

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

Return Value

bool True if gettext is native

at line 105
protected setNativeGettextLocale(string $locale)

Set native locale for getText.

Parameters

string $locale

at line 129
protected setPhpGettextLocale(string $locale)

Set getText locale.

Parameters

string $locale

at line 159
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 215
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 237
static string getResourceDir()

Get the directory for l10n resources.

Return Value

string

at line 270
string crm_translate(string $text, array $params = array())

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

Return Value

string the translated string

at line 366
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 456
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 468
localizeArray(array $array, array $params = array())

Localize (destructively) array values.

Parameters

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

at line 491
localizeTitles(array $array)

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

Parameters

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

at line 512
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 567
static Bool isMultilingual()

Is the CiviCRM in multilingual mode.

Return Value

Bool True if CiviCRM is in multilingual mode.

at line 582
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 596
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 621
static CRM_Core_I18n singleton()

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

Return Value

CRM_Core_I18n

at line 638
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 660
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 683
static string getLocale()

Get the current locale

Return Value

string