Download the PHP package webiik/translation without Composer
On this page you can find all versions of the php package webiik/translation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webiik/translation
More information about webiik/translation
Files in webiik/translation
Package translation
Short Description The Translation provides i18n translation.
License MIT
Homepage https://www.webiik.com
Informations about the package translation
Translation
The translation provides i18n with user-extensible translation formatting.
Installation
Example
Setting
setLang
setLang() sets current lang of translation. This lang is used for setting and getting values to/from Translation class.
inject
inject() injects dependencies to specific parser. It is useful when you make your custom parser and you need to inject some external dependencies.
Adding
add
add() adds translation by key. Read more about supported translation formats.
addArr
addArr() adds translations from array.
Note about resolving the key conflicts:
Arrays values - New value that is an array is merged with old value that is an array. If array key is a string, value of the new key replaces value of the old key.
Mixed values - New value that is a different type than old value, replaces old value. e.g. New string value replaces old array value and vice-versa.
Getting
get
get() gets translation by key. Key supports dot notation. If key is missing it returns empty string. After calling, all missing keys and contexts can be obtained with method getMissing().
getAll
getAll() gets all translations. After calling, all missing contexts can be obtained with method getMissing().
getMissing
getMissing() returns array of all missing keys and contexts from callings of methods get() and getAll().
Parsing
Translations can contain special formatting which help to update translation values on the fly.
Basic Syntax
You can add any variable to translation with folded brackets.
Plural Syntax
Sometimes a translation depends on some specific count. Int allowed values are: int, int-int, int-, int+
Select Syntax
Sometimes a translation depends on some specific value. In the select syntax, string represents that value.
Link Syntax
If you need to generate links and don't want to use HTML.
⚠️ Notice the true parameter when calling the method
get
. Without it, the link would be not generated, and the text of translation would be displayed in the original format.
Custom Parser Syntax
or
You can write your own parser. Every custom parser must:
- be compatible with the syntax above
- implement Webiik\Translation\Parser\ParserInterface.php
- use namespace Webiik\Translation\Parser
Look at Select parser to get better insight.