paquettg/i18n

A stand alone i18n php library.

1.0.1 2018-12-20 20:04 UTC

This package is auto-updated.

Last update: 2024-11-05 18:20:40 UTC


README

Version 1.0.1

Build Status Coverage Status

I18n is a php framework agnostic package to handle I18n functionality (such an original name). The goal is to have the ability to implement multiple languages into a website with out needing to depend on a framework.

Install

This package can be found on packagist and is best loaded using composer. We support PHP 7.1, 7.2, and 7.3.

Simple Example

You can find many examples of how to use the package and any of its parts (which you will most likely never touch) in the tests directory. The tests are done using PHPUnit and are very small, a few lines each, and are a great place to start. Given that, I'll still be showing examples of how the package is intended to work. The following example is a very simplistic usage of the package, good place to start.

use I18n\I18n;

$i18n = new I18n;
$i18n->set([
	'foo' => 'bar',
	'baz' => [
		'rawr' => 'meow?',
	],
], 'en_CA');
$i18n->load('en_CA');

echo $i18n->get('baz.rawr'); // will output 'meow?'

You may also set a directory to look at to load the given locales.

use I18n\I18n;

$i18n = new I18n;
$i18n->load($pathToLocaleDirectory);
$i18n->load($locale);

Using static facade

We also support a static facade so you don't need to carry around the I18n object to every part of your application.

use I18n\Facade\StaticI18n;

StaticI18n::mount();
I18n::set([
	'foo' => 'bar',
	'baz' => [
		'rawr' => 'meow?',
	],
], 'en_CA');
I18n::load('en_CA');
echo I18n::get('baz.rawr');