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
)
string
name of the class (with namespace) to use
string
locale 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.
boolean
TRUE 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.
boolean
TRUE for display report after generate
array<mixed,string>
list of initialized localesget(string $locale = NULL
) : \stdClass
string
locale to retrieve or NULL for use the last initialized locale
\stdClass
a class for use the specified localegetCurrentLocale() : string
string
current localegetInstance(string $name, string $rootPath= NULL
, integer $mode= self::MODE_REGENERATE_ON_THE_FLY
) : static
string
name of the I18n instance to retrieve
string
absolute path of an application. Can be used to quickly initialize cache and lang paths.
integer
set it to a self::MODE_* value for change how locales classes are loaded
static
init(string|array<mixed,string> $locales) : static
string
array<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 |
---|
static
current instanceisGenerationMode(integer $mode) : boolean
integer
a generation mode
boolean
TRUE if current generation mode is $modesetCachePath(string $path) : \salt\I18n
string
absolute path that will contains PHP classes
\salt\I18n
current instancesetLangPath(string $path) : \salt\I18n
string
absolute path that contains yaml files
\salt\I18n
current instance__construct(string $name, string $path, integer $mode)
string
Application name
string
absolute path of the application
integer
set 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
string
the separator for merge sub keys
string
internal 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
string
prefix of all keys, do not use on first call
array<mixed,string>
all computed keys, internal calls only
string
PHP 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>
string
locale 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
string
original filename that contains raw data (yaml localization file)
string
namespace of the class
string
name of the class
string
name of the parent class (of same namespace)
array<mixed,mixed>
array as key=>value, value can be an array
string
additionnal information on generation
string
PHP code of the classgenerateClass(string $source, string $destination, string $namespace, string $locale, string $parent)
string
locale file
string
destination file
string
namespace of the class
string
locale to generate
string
parent locale
generateHtaccess(string $dir)
string
directory
initLocale(string $locale, boolean $forceGenerate = FALSE
) : static
string
locale to initialize
boolean
TRUE for generate class file for MODE_USE_GENERATED mode
static
current I18n or NULL if locale does not existsnormalizeKey(string $key) : string
string
key in locale file
string
normalized keynormalizeLocale(string $locale) : string
string
raw locale like en-US
string
normalized locale like en_usretrieveClassesToCreate(string $locale, boolean $parent = FALSE
) : array<mixed,mixed>
string
locale
boolean
TRUE if is parent locale
array<mixed,mixed>
array locale => yamlFilePath. yamlFilePath is NULL if the file don't existrootLocale(string $locale) : string
string
locale like xx_yy
string
root 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
NULL
DEBUG = 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'