Download the PHP package krisanalfa/bono-lang without Composer
On this page you can find all versions of the php package krisanalfa/bono-lang. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package bono-lang
Bono Localization Package
Want some translation in your Bono-Based Application? Use this component. Code like a boss.
Installation
Add this package to composer.json
require file:
Activate Localization Package
Put the Provider to your bono.providers
configuration:
Configuration
Basic configuration is:
driver
is a class that responsible to get all list of registered Language and get words for each language available in listlang
is active language you want to use to translate, you can use aclosure
to set the default language, see example belowdebug
when you set this config tofalse
, and you get nothing from translation, the result is empty string, but if it sets totrue
, you get some debug keyword
Using closure to determine which language is set to be default one
Basic FileDriver Dictionary Knowledge
You can change the location of your dictionary, by add lang.path
in configuration files:
So in your root project, you should create a lang
folder , and put your dictionary inside that folder.
When you want Spanish language exists in your repository, make an es
folder in lang
folder. The structure of your dictionary should be like this:
Example dictionary
Let's say this is our dictionary
Usage (Based on example dictionary)
You can access translation from application container context, such as:
Or via alias function:
You can append some parameter to your language. But, first, you have to confirm that your line, accept the parameter by change it to
So you can append parameter to your dictionary by:
The third argument in translate
method is option to give translator a default translation if there's no translation in dictionary:
When you want to access your nested dictionary:
This package also support for choice if there's multiple message in a key, something like this:
If you want to take Sagara
in options
key, you can access them by:
You can also put any placeholder in choice
, something like this:
The count
variable is automatically appended in choice
method: