Handle message translation
1) Initialize application
$i18n = I18n::getInstance(NAME, APPLICATION PATH);
retrieve next instances with $i18n = I18n::getInstance(NAME);
2) Retrieve locales
$en = $i18n->init(LOCALE)->get();
or: $i18n->init(LOCALE)->alias('L');
3) Retrieve text
$en::KEY
or: L::KEY
For better performance :
| package | salt\utils |
|---|
alias(string $alias, string $locale = NULL)
stringname of the class (with namespace) to use
stringlocale to alias, if not provided, use the locale of the last init() call
check(boolean $display = FALSE) : array<mixed,mixed>
Display keys missing or not defined in default locale for each locale files
DO NOT CALL this method at each page ! You have to call it only once, after a language file was modified.
booleanTRUE for display check report
array<mixed,mixed>Report as :generate(boolean $display = FALSE) : array<mixed,string>
DO NOT CALL this method at each page ! You have to call it only once, after a language file was modified
If you don't want to do this, use I18n::MODE_REGENERATE_ON_THE_FLY in getInstance() instead.
booleanTRUE for display report after generate
array<mixed,string>list of initialized localesget(string $locale = NULL) : \stdClass
stringlocale to retrieve or NULL for use the last initialized locale
\stdClassa class for use the specified localegetCurrentLocale() : string
stringcurrent localegetInstance(string $name, string $rootPath= NULL, integer $mode= self::MODE_REGENERATE_ON_THE_FLY) : static
stringname of the I18n instance to retrieve
stringabsolute path of an application. Can be used to quickly initialize cache and lang paths.
integerset it to a self::MODE_* value for change how locales classes are loaded
staticinit(string|array<mixed,string> $locales) : static
stringarray<mixed,string>locale to load, in preference order. Load the first available locale.
Generic locale has not required.
init('en_us') is equivalent to init(array('en_us', 'en'))
\salt\SaltException |
|---|
staticcurrent instanceisGenerationMode(integer $mode) : boolean
integera generation mode
booleanTRUE if current generation mode is $modesetCachePath(string $path) : \salt\I18n
stringabsolute path that will contains PHP classes
\salt\I18ncurrent instancesetLangPath(string $path) : \salt\I18n
stringabsolute path that contains yaml files
\salt\I18ncurrent instance__construct(string $name, string $path, integer $mode)
stringApplication name
stringabsolute path of the application
integerset it to a self::MODE_* value for change how locales classes are loaded
array_keys_recursive(array<mixed,mixed> $array, string $separator, string $prefix = '') : array<mixed,string>
array<mixed,mixed>multi dimensionnal array
stringthe separator for merge sub keys
stringinternal prefix for recursivity
array<mixed,string>key list. If a value is an array, all array keys will be added with a prefix : the current key and $separator.buildData(array<mixed,mixed> $data, string $keyPrefix= '', array<mixed,string> $allKeys= array()) : string
array<mixed,mixed>array as key=>value, value can be an array
stringprefix of all keys, do not use on first call
array<mixed,string>all computed keys, internal calls only
stringPHP code with all leaf of $data as constant and all node of $data as static function that return an arraycheckNoneLocaleInitialized()
\salt\SaltException |
if method init() was called |
|---|
compatibleLocales(string $locale) : array<mixed,string>
stringlocale like xx-yy
array<mixed,string>array of locales, for example [xx-yy, xx]convertToClass(string $source, string $namespace, string $className, string $parent, array<mixed,mixed> $data, string $generationInfos) : string
stringoriginal filename that contains raw data (yaml localization file)
stringnamespace of the class
stringname of the class
stringname of the parent class (of same namespace)
array<mixed,mixed>array as key=>value, value can be an array
stringadditionnal information on generation
stringPHP code of the classgenerateClass(string $source, string $destination, string $namespace, string $locale, string $parent)
stringlocale file
stringdestination file
stringnamespace of the class
stringlocale to generate
stringparent locale
generateHtaccess(string $dir)
stringdirectory
initLocale(string $locale, boolean $forceGenerate = FALSE) : static
stringlocale to initialize
booleanTRUE for generate class file for MODE_USE_GENERATED mode
staticcurrent I18n or NULL if locale does not existsnormalizeKey(string $key) : string
stringkey in locale file
stringnormalized keynormalizeLocale(string $locale) : string
stringraw locale like en-US
stringnormalized locale like en_usretrieveClassesToCreate(string $locale, boolean $parent = FALSE) : array<mixed,mixed>
stringlocale
booleanTRUE if is parent locale
array<mixed,mixed>array locale => yamlFilePath. yamlFilePath is NULL if the file don't existrootLocale(string $locale) : string
stringlocale like xx_yy
stringroot locale like xx$_saltCachePath : string
NULL$_saltGenerationMode : integer
self::MODE_REGENERATE_ON_THE_FLY$_saltInitializedLocales : array<mixed,string>
array()$_saltInstances : array<mixed,\salt\I18n>
array()$_saltLangPath : string
NULL$_saltLocale : string
self::DEFAULT_LOCALE$_saltName : string
NULLDEBUG = FALSE
DEFAULT_CACHE_PATH = 'cache'
DEFAULT_LANG_PATH = 'lang'
DEFAULT_LOCALE = 'en'
EXTENSION = 'yml'
MODE_REGENERATE_ON_THE_FLY = 1
MODE_USE_GENERATED = 2
SPYC_PATH = 'vendor/spyc-0.5.1/Spyc.php'