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
generate()
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.
get(string $locale = NULL) : \stdClass
stringlocale to retrieve or NULL for use the last initialized locale
\stdClassa class for use the specified 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 instancesetCachePath(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
buildData(array<mixed,mixed> $data, string $keyPrefix = '') : string
array<mixed,mixed>array as key=>value, value can be an array
stringprefix of all keys, do not use on first call
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) : static
stringlocale to initialize
staticcurrent I18n or NULL if locale does not existsnormalizeLocale(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_FORCE_GENERATION = FALSE
DEFAULT_CACHE_PATH = 'cache'
DEFAULT_LANG_PATH = 'lang'
DEFAULT_LOCALE = 'en'
EXTENSION = 'yml'
MODE_FORCE_REGENERATE = -1
MODE_REGENERATE_ON_THE_FLY = 1
MODE_USE_GENERATED = 2
SPYC_PATH = 'vendor/spyc-0.5.1/Spyc.php'