fyre / lang
A language utility library.
v5.1.0
2024-11-20 13:46 UTC
Requires
- fyre/array: ^2.0
- fyre/config: ^4.1
- fyre/path: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.59
- fyre/php-cs-fixer-config: ^1.0
- phpunit/phpunit: ^11
README
FyreLang is a free, open-source language library for PHP.
Table Of Contents
Installation
Using Composer
composer require fyre/lang
In PHP:
use Fyre\Lang\Lang;
Basic Usage
$config
is a Config.
$lang = new Lang($config);
The default locale will be resolved from the "App.defaultLocale" key in the Config.
Autoloading
It is recommended to bind the Lang to the Container as a singleton.
$container->singleton(Lang::class);
Any dependencies will be injected automatically when loading from the Container.
$lang = $container->use(Lang::class);
Methods
Add Path
Add a language path.
$path
is a string representing the path to add.$prepend
is a boolean indicating whether to prepend the file path, and will default to false.
$lang->addPath($path, $prepend);
Clear
Clear all language data.
$lang->clear();
Get
Get a language value.
$key
is a string representing the key to lookup.$data
is an array containing data to insert into the language string.
$lang = $lang->get($key, $data);
See the MessageFormatter::formatMessage method for details about message formatting.
Get Default Locale
Get the default locale.
$defaultLocale = $lang->getDefaultLocale();
Get Locale
Get the current locale.
$locale = $lang->getLocale();
Get Paths
Get the paths.
$paths = $lang->getPaths();
Remove Path
Remove a path.
$path
is a string representing the path to remove.
$lang->removePath($path);
Set Default Locale
Set the default locale.
$locale
is a string representing the locale.
$lang->setDefaultLocale($locale);
Set Locale
Set the current locale.
$locale
is a string representing the locale.
$lang->setLocale($locale);