$_fallback_language
$_fallback_language : string
Fallback language, in case the selected language is not available.
This is a basic MidCOM Service which provides an interfaces to the various I18n facilities of MidCOM.
The I18n service serves as a central access point for all aspects around internationalization and localization. It provides auto-detection of language data using HTTP Content-Negotiation along with a cookie-based fallback.
This class is able to run independently from midcom_application due to the fact that it is used in the cache_hit code.
Use this class to set the language preferences (charset and locale) and to gain access to the l10n string databases. A few helpers which can be used to ease translation work (like charset conversion) are in here as well.
All language codes used here are ISO 639-1 two-letter codes.
$_obj_l10n : array<mixed,\midcom_services_i18n_l10n>
Cache of all instantiated localization classes.
__construct()
Initialize the available i18n framework by determining the desired language from these different sources: HTTP Content Negotiation, Client side language cookie.
Its two parameters set the default language in case that none is supplied via HTTP Content Negotiation or through Cookies.
The default language set on startup is currently hardcoded to 'en', you should override it after initialization, if you want something else using the setter methods below.
The fallback language is read from the MidCOM configuration directive i18n_fallback_language.
set_language(string $lang)
Set output language.
This will set the character encoding to the language's default encoding and will also set the system locale to the one specified in the language database.
If you want another character encoding as the default one, you have to override it manually using midcom_services_i18n::set_charset() after calling this method.
string | $lang | Language ISO 639-1 code |
get_l10n(string $component = 'midcom', string $database = 'default') : \midcom_services_i18n_l10n
Returns a l10n class instance which can be used to access the localization data of the current component.
Using the special name "midcom" you will get the midcom core l10n library.
string | $component | The component for which to retrieve a string database. |
string | $database | The string table to retrieve from the component's locale directory. |
The cached L10n database
get_string(string $stringid, string $component = null, string $database = 'default') : string
Returns a translated string using the l10n database specified in the function arguments.
string | $stringid | The string to translate. |
string | $component | The component for which to retrieve a string database. If omitted, this defaults to the current component (out of the component context). |
string | $database | The string table to retrieve from the component's locale directory. If omitted, the 'default' database is used. |
The translated string
show_string(string $stringid, string $component = null, string $database = 'default')
This is a shortcut for echo $this->get_string(.
..);.
To keep the naming stable with the actual l10n class, this is not called echo_string (Zend won't allow $l10n->echo().)
string | $stringid | The string to translate. |
string | $component | The component for which to retrieve a string database. If omitted, this defaults to the current component (out of the component context). |
string | $database | The string table to retrieve from the component's locale directory. If omitted, the 'default' database is used. |
convert_to_current_charset(string $string, string $charset = null) : string
Converts the given string to the current site charset.
The charset should be specified explicitly, as autodetection is very very error prone (though sometimes you don't have a choice).
string | $string | The string to convert. |
string | $charset | The charset in which string currently is, omit this parameter to use mb_detect_encoding (error prone!) |
The converted string.
_load_l10n_db(string $component, string $database)
Load the specified l10n library.
If loading the library failed, midcom_error is thrown, otherwise the l10n db cache is populated accordingly.
string | $component | The component for which to retrieve a string database. |
string | $database | The string table to retrieve from the component's locale directory. |
iconv(string $source_charset, string $destination_charset, string $string) : mixed
This is a calling wrapper to the iconv library.
See the PHP iconv() function for the exact parameter definitions.
string | $source_charset | The charset to convert from. |
string | $destination_charset | The charset to convert to. |
string | $string | The string to convert. |
The converted string or false on any error.