fyre/lang

A language utility library.

v4.0.3 2024-10-30 11:52 UTC

This package is auto-updated.

Last update: 2024-10-30 11:53:35 UTC


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);