Localization
class Localization (View source)
Constants
BASE_LOCALE |
The "base" locale identifier. |
CONTEXT_SYSTEM |
The context (resolving to en_US) to be considered as the "neutral" one. This context must be used for all strings that are system related in concrete5 and should have their own context. Generally, these are the strings that concrete5 saves in the database, such as package, theme and block type names/descriptions. |
CONTEXT_SITE |
This is the context for the site interface tranlations. It contains the page locale, determined by the page-specific locale or by the site section it's contained in. When there's no locale associated to the current page, this context is associated to the locale specified in the concrete.locale configuration option. These are all the translations that the site visitors see on the site. The editor also sees these strings in the same language as the visitor. |
CONTEXT_UI |
The context containing the locale of the current user (fallsback to the concrete.locale configuration option). This should be the context used when showing the edit dialogs, the concrete5 menus... |
Properties
protected TranslatorAdapterRepositoryInterface | $translatorAdapterRepository | The translator adapter repository to be used. |
|
protected array | $contextLocales | The locale identifier to be used for every translation context. |
|
protected string|null | $activeContext | The currently active translation context. |
|
protected array | $activeContextQueue | Tracks the list of active contexts. |
Methods
Gets the translator adapter repository.
Sets the translator adapter repository.
Returns the currently active translation context.
Sets the active translation context.
Change the active translation context, but remember the previous one.
Restore the context that was active before calling pushActiveContext.
Execute a function using a specific localization context.
Gets the translator adapter object for the given context from the translator adapter repository.
Gets the translator adapter for the active context.
Sets the context locale for the given context as the given locale.
Gets the context locale for the given context.
Sets the locale for the active context.
Gets the locale for the active context.
Removes all the loaded translator adapters from the translator adapter repository.
Gets a singleton instance of this class.
Gets the translator object for the active context from from the singleton instance of this class.
Sets the locale for the active context for the singleton instance of this class.
Returns the currently active locale for the currently active context from the singleton instance of this class.
Returns the language for the currently active locale for the currently active context from the singleton instance of this class.
Gets a list of the available site interface languages. Returns an array that where each item is a locale in format xx_XX.
Generates a list of all available languages and returns an array like [ "de_DE" => "Deutsch (Deutschland)", "en_US" => "English (United States)", "fr_FR" => "Francais (France)"] The result will be sorted by the key.
Get the description of a locale consisting of language and region description e.g. "French (France)".
Clear the translations cache.
Load the site language files (must be done after all packages called their setupPackageLocalization).
To be called every time the current locale changes.
Details
TranslatorAdapterRepositoryInterface
getTranslatorAdapterRepository()
Gets the translator adapter repository.
setTranslatorAdapterRepository(TranslatorAdapterRepositoryInterface $repository)
Sets the translator adapter repository.
string
getActiveContext()
Returns the currently active translation context.
setActiveContext(string $context)
Sets the active translation context.
pushActiveContext(string $newContext)
Change the active translation context, but remember the previous one.
Useful when temporarily setting the translation context to something else than the original.
popActiveContext()
Restore the context that was active before calling pushActiveContext.
mixed
withContext(string $context, callable $callback)
Execute a function using a specific localization context.
TranslatorAdapterInterface
getTranslatorAdapter($context)
Gets the translator adapter object for the given context from the translator adapter repository.
TranslatorAdapterInterface
getActiveTranslatorAdapter()
Gets the translator adapter for the active context.
setContextLocale(string $context, string $locale)
Sets the context locale for the given context as the given locale.
string|null
getContextLocale($context)
Gets the context locale for the given context.
setLocale(string $locale)
Sets the locale for the active context.
string
getLocale()
Gets the locale for the active context.
removeLoadedTranslatorAdapters()
Removes all the loaded translator adapters from the translator adapter repository.
Translator|null
getActiveTranslateObject()
deprecated
deprecated
Gets the translator object for the active context.
static Localization
getInstance()
Gets a singleton instance of this class.
static Translator
getTranslate()
deprecated
deprecated
Gets the translator object for the active context from from the singleton instance of this class.
static
changeLocale(string $locale)
Sets the locale for the active context for the singleton instance of this class.
static string
activeLocale()
Returns the currently active locale for the currently active context from the singleton instance of this class.
static string
activeLanguage()
Returns the language for the currently active locale for the currently active context from the singleton instance of this class.
static array
getAvailableInterfaceLanguages()
Gets a list of the available site interface languages. Returns an array that where each item is a locale in format xx_XX.
static array
getAvailableInterfaceLanguageDescriptions(string|null $displayLocale = '')
Generates a list of all available languages and returns an array like [ "de_DE" => "Deutsch (Deutschland)", "en_US" => "English (United States)", "fr_FR" => "Francais (France)"] The result will be sorted by the key.
If the $displayLocale is set, the language- and region-names will be returned in that language.
static string
getLanguageDescription(string $locale, string|null $displayLocale = '')
Get the description of a locale consisting of language and region description e.g. "French (France)".
static
clearCache()
Clear the translations cache.
static
setupSiteLocalization(Translator $translate = null)
deprecated
deprecated
Load the site language files (must be done after all packages called their setupPackageLocalization).
protected
currentLocaleChanged(string $locale)
To be called every time the current locale changes.