CRM_Core_I18n
in package
Tags
Table of Contents
Constants
- AUTO = 'auto'
- Constants for communication preferences.
- NONE = 'none'
- Constants for communication preferences.
Properties
- $SQL_ESCAPER : string
- $_extensioncache : array<string|int, mixed>
- Gettext cache for extension domains/streamers, depending on if native or phpgettext.
- $_nativegettext : bool
- Whether we are using native gettext or not.
- $_phpgettext : object
- A PHP-gettext instance for string translation; should stay null if the strings are not to be translated (en_US).
- $locale : string
Methods
- __construct() : CRM_Core_I18n
- A locale-based constructor that shouldn't be called from outside of this class (use singleton() instead).
- clearLocale() : void
- crm_translate() : string
- Smarty block function, provides gettext support for smarty.
- getContactDefaultLanguage() : string
- Get the default language for contacts where no language is provided.
- getFormatLocales() : array<string|int, mixed>
- Get the options available for format locale.
- getLocale() : string
- Get the current locale
- getMultilingual() : array<string|int, mixed>|bool
- Returns languages if domain is in multilingual mode.
- getResourceDir() : string
- Get the directory for l10n resources.
- isLanguageRTL() : bool
- Is the language written "right-to-left"?
- isMultilingual() : bool
- Is the current CiviCRM domain in multilingual mode.
- isNative() : bool
- Returns whether gettext is running natively or using PHP-Gettext.
- languages() : array<string|int, mixed>
- Return languages available in this instance of CiviCRM.
- localizeArray() : mixed
- Localize (destructively) array values.
- localizeTitles() : mixed
- Localize (destructively) array elements with keys of 'title'.
- setGettextDomain() : bool
- Binds a gettext domain, wrapper over bindtextdomain().
- setLcTime() : string
- Set the LC_TIME locale if it's not set already (for a given language choice).
- setLocale() : mixed
- Change the processing language without changing the current user language
- singleton() : CRM_Core_I18n
- Static instance provider - return the instance for the current locale.
- strarg() : string
- Replace arguments in a string with their values. Arguments are represented by % followed by their number.
- translate() : string
- Translate a string to the current locale.
- uiLanguages() : array<string|int, mixed>|string
- Return the available UI languages
- crm_translate_raw() : string
- Lookup the raw translation of a string (without any extra escaping or interpolation).
- escape() : string
- Escape a string if a mode is specified, otherwise return string unmodified.
- reactivate() : mixed
- If you switch back/forth between locales/drivers, it may be necessary to reset some options.
- setNativeGettextLocale() : mixed
- Set native locale for getText.
- setPhpGettextLocale() : mixed
- Set getText locale.
- getWordReplacements() : array<string|int, mixed>
Constants
AUTO
Constants for communication preferences.
public
string
AUTO
= 'auto'
NONE
Constants for communication preferences.
public
string
NONE
= 'none'
Properties
$SQL_ESCAPER
This variable has 1-2 references in contrib, which -probably- aren't functionally necessary. (Extensions don't load in pre-installation environments...) But we'll keep the property stub just to prevent crashes.
Replaced by $GLOBALS['CIVICRM_SQL_ESCAPER'].
public
static string
$SQL_ESCAPER
= \NULL
$_extensioncache
Gettext cache for extension domains/streamers, depending on if native or phpgettext.
private
array<string|int, mixed>
$_extensioncache
= []
- native gettext: we cache the value for textdomain()
- phpgettext: we cache the file streamer.
$_nativegettext
Whether we are using native gettext or not.
private
bool
$_nativegettext
= \FALSE
$_phpgettext
A PHP-gettext instance for string translation; should stay null if the strings are not to be translated (en_US).
private
object
$_phpgettext
= \NULL
$locale
private
string
$locale
Methods
__construct()
A locale-based constructor that shouldn't be called from outside of this class (use singleton() instead).
public
__construct(string $locale) : CRM_Core_I18n
Parameters
- $locale : string
-
the base of this certain object's existence.
Return values
CRM_Core_I18nclearLocale()
public
static clearLocale() : void
crm_translate()
Smarty block function, provides gettext support for smarty.
public
crm_translate(string $text[, array<string|int, mixed> $params = [] ]) : string
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
- $text : string
-
the original string.
- $params : array<string|int, mixed> = []
-
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 values
string —the translated string
getContactDefaultLanguage()
Get the default language for contacts where no language is provided.
public
static getContactDefaultLanguage() : string
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 values
stringgetFormatLocales()
Get the options available for format locale.
public
static getFormatLocales() : array<string|int, mixed>
Note the pseudoconstant can't be used as the key is the name not the value.
Return values
array<string|int, mixed>getLocale()
Get the current locale
public
static getLocale() : string
Return values
stringgetMultilingual()
Returns languages if domain is in multilingual mode.
public
static getMultilingual() : array<string|int, mixed>|bool
Return values
array<string|int, mixed>|boolgetResourceDir()
Get the directory for l10n resources.
public
static getResourceDir() : string
Return values
stringisLanguageRTL()
Is the language written "right-to-left"?
public
static isLanguageRTL(string $language) : bool
Parameters
- $language : string
-
Language (for example 'en_US', or 'fr_CA').
Return values
bool —True if it is an RTL language.
isMultilingual()
Is the current CiviCRM domain in multilingual mode.
public
static isMultilingual() : bool
Return values
bool —True if CiviCRM is in multilingual mode.
isNative()
Returns whether gettext is running natively or using PHP-Gettext.
public
isNative() : bool
Return values
bool —True if gettext is native
languages()
Return languages available in this instance of CiviCRM.
public
static languages([bool $justEnabled = FALSE ]) : array<string|int, mixed>
Parameters
- $justEnabled : bool = FALSE
-
whether to return all languages or just the enabled ones.
Return values
array<string|int, mixed> —Array of code/language name mappings
localizeArray()
Localize (destructively) array values.
public
localizeArray(array<string|int, mixed> &$array[, array<string|int, mixed> $params = [] ]) : mixed
Parameters
- $array : array<string|int, mixed>
-
the array for localization (in place).
- $params : array<string|int, mixed> = []
-
an array of additional parameters.
localizeTitles()
Localize (destructively) array elements with keys of 'title'.
public
localizeTitles(array<string|int, mixed> &$array) : mixed
Parameters
- $array : array<string|int, mixed>
-
the array for localization (in place).
setGettextDomain()
Binds a gettext domain, wrapper over bindtextdomain().
public
setGettextDomain(string $key) : bool
Parameters
- $key : string
-
Key of the extension (can be 'civicrm', or 'org.example.foo').
Return values
bool —True if the domain was changed for an extension.
setLcTime()
Set the LC_TIME locale if it's not set already (for a given language choice).
public
static setLcTime() : string
Return values
string —the final LC_TIME that got set
setLocale()
Change the processing language without changing the current user language
public
setLocale(string|Locale $locale) : mixed
Parameters
- $locale : string|Locale
-
Locale (for example 'en_US', or 'fr_CA'). True if the domain was changed for an extension.
singleton()
Static instance provider - return the instance for the current locale.
public
static & singleton() : CRM_Core_I18n
Return values
CRM_Core_I18nstrarg()
Replace arguments in a string with their values. Arguments are represented by % followed by their number.
public
strarg(string $str) : string
Parameters
- $str : string
-
source string.
Return values
string —modified string
translate()
Translate a string to the current locale.
public
translate(string $string) : string
Parameters
- $string : string
-
this string should be translated.
Return values
string —the translated string
uiLanguages()
Return the available UI languages
public
static uiLanguages([mixed $justCodes = FALSE ]) : array<string|int, mixed>|string
Parameters
- $justCodes : mixed = FALSE
Return values
array<string|int, mixed>|string —array(string languageCode => string languageName) if !$justCodes
crm_translate_raw()
Lookup the raw translation of a string (without any extra escaping or interpolation).
protected
crm_translate_raw(string $text, string|null $domain, int|null $count, string $plural, string $context) : string
Parameters
- $text : string
- $domain : string|null
- $count : int|null
- $plural : string
- $context : string
Return values
stringescape()
Escape a string if a mode is specified, otherwise return string unmodified.
protected
static escape(string $text, string $mode) : string
Parameters
- $text : string
- $mode : string
Return values
stringreactivate()
If you switch back/forth between locales/drivers, it may be necessary to reset some options.
protected
reactivate() : mixed
setNativeGettextLocale()
Set native locale for getText.
protected
setNativeGettextLocale(string $locale) : mixed
Parameters
- $locale : string
setPhpGettextLocale()
Set getText locale.
protected
setPhpGettextLocale(string $locale) : mixed
Since CiviCRM 4.5, expected dir structure is civicrm/l10n/xx_XX/LC_MESSAGES/civicrm.mo because that is what native gettext expects. Fallback support for the pre-4.5 structure was removed in CiviCRM 5.51.
CiviCRM 5.23 added support for the CIVICRM_L10N_BASEDIR constant (and [civicrm.l10n]) so that mo files can be stored elsewhere (such as in a web-writable directory, to support extensions sur as l10nupdate.
Parameters
- $locale : string
getWordReplacements()
private
getWordReplacements() : array<string|int, mixed>
Return values
array<string|int, mixed> —Ex: $stringTable['enabled']['wildcardMatch']['foo'] = 'bar';