- Openclerk\I18n
class Openclerk \ I18n
A simple class to support internationalisation (i18n) through the t() method. The locale needs to be loaded at runtime either through session data, cookies, databases etc. Also see the methods for getting the list of available locales.
Method Summary
Name | Description |
---|---|
addAvailableLocale(Locale $locale) | Locales can be defined through a number of different ways at runtime; one way is through component-discovery, for example. Here, locales can be registered. |
addAvailableLocales($locales) | Add a mapping of (key => locale)s, useful for component-discovery |
addDefaultKeys($keys) | Add default keys to all strings, e.g. :site_name |
getAvailableLocales() | |
getCurrentLocale() | Get the current locale, or 'en' if none is defined. |
plural($string, $strings, $number = false, $decimals = 0) | Return the plural of something. e.g. plural('book', 1), plural('book', 'books', 1), plural('book', 1000) |
resetAvailableLocales() | |
setLocale($code = null) | |
stripKey($key) | remove any unnecessary whitespace in the key that won't be displayed |
t($category, $key = false, $args = array()) |
Translate a given 'en' string into the current locale. Loads locale data from __DIR__ . "/../locale/" . $locale . ".php" . |
tWithoutCategory($key = false, $args = array()) |
static function addAvailableLocale(Locale $locale)
Locales can be defined through a number of different ways at runtime; one way is through component-discovery, for example. Here, locales can be registered.
static function addAvailableLocales($locales)
Add a mapping of (key => locale)s, useful for component-discovery
- See:
static function addDefaultKeys($keys)
Add default keys to all strings, e.g. :site_name
static function getAvailableLocales()
static function getCurrentLocale()
Get the current locale, or 'en' if none is defined.
static function plural($string, $strings, $number = false, $decimals = 0)
Return the plural of something. e.g. plural('book', 1), plural('book', 'books', 1), plural('book', 1000)
- Defaults:
number
=false
decimals
= 0
static function resetAvailableLocales()
static function setLocale($code = null)
- Parameters:
$code
- string the locale code to set to, ornull
to reset it to default- Defaults:
code
=null
static function stripKey($key)
remove any unnecessary whitespace in the key that won't be displayed
- Returns:
the key with all leading, trailing and multiple inline spaces removed
static function t($category, $key = false, $args = array())
Translate a given 'en' string into the current locale. Loads locale data from
__DIR__ . "/../locale/" . $locale . ".php"
.If the given string does not exist in the locale then call
missing_locale_string($key, $locale)
(if the function exists) and return the default translation (in 'en').
- Defaults:
key
=false
args
= array()- See:
setLocale($locale)
static function tWithoutCategory($key = false, $args = array())
- Defaults:
key
=false
args
= array()