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
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
string
locale to retrieve or NULL for use the last initialized locale
\stdClass
a class for use the specified 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 instancesetCachePath(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
buildData(array<mixed,mixed> $data, string $keyPrefix = ''
) : string
array<mixed,mixed>
array as key=>value, value can be an array
string
prefix of all keys, do not use on first call
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) : static
string
locale to initialize
static
current I18n or NULL if locale does not existsnormalizeLocale(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_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'