fyre / lang
A language utility library.
v4.0.3
2024-10-30 11:52 UTC
Requires
- fyre/array: ^2.0
- 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
$paths
is an array containing the paths, and will default to [].$locale
is a string representing the locale, and will default to null.$defaultLocale
is a string representing the default locale, and will default to null.
$lang = new Lang($paths, $locale, $defaultLocale);
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);