Skip to content

Commit

Permalink
docs: README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Mar 21, 2021
1 parent 338180a commit b134cd9
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

PHP library/api to provide Internationalisation and Localisation

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/0e211604213247da98198bb1f894a92e)](https://www.codacy.com/app/wdes/php-I18n-L10n?utm_source=github.com&utm_medium=referral&utm_content=wdes/php-I18n-L10n&utm_campaign=Badge_Grade)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/2c22d6f405d143d8b65d0e1d875dd701)](https://www.codacy.com/gh/wdes/php-I18n-L10n/dashboard?utm_source=github.com&utm_medium=referral&utm_content=wdes/php-I18n-L10n&utm_campaign=Badge_Grade)
![Lint and analyse files](https://github.com/wdes/php-I18n-L10n/workflows/Lint%20and%20analyse%20files/badge.svg?branch=main)
![Run phpunit tests](https://github.com/wdes/php-I18n-L10n/workflows/Run%20phpunit%20tests/badge.svg?branch=main)
[![codecov](https://codecov.io/gh/wdes/php-I18n-L10n/branch/main/graph/badge.svg)](https://codecov.io/gh/wdes/php-I18n-L10n)
Expand All @@ -15,6 +15,10 @@ PHP library/api to provide Internationalisation and Localisation

[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fwdes%2Fphp-I18n-L10n.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fwdes%2Fphp-I18n-L10n?ref=badge_large)

## About

We use the [`phpmyadmin/twig-i18n-extension`](https://github.com/phpmyadmin/twig-i18n-extension#readme) for the Twig extension.

## How to use

```sh
Expand All @@ -23,6 +27,42 @@ composer require wdes/php-i18n-l10n

Have a look at example file [example/simple.php](example/simple.php)

### Example

```php
<?php
declare(strict_types = 1);
// Can be removed :)

require_once __DIR__ . '/../vendor/autoload.php';

use \Wdes\phpI18nL10n\plugins\MoReader;
use \Wdes\phpI18nL10n\Launcher;
use \Wdes\phpI18nL10n\Twig\Extension\I18n as ExtensionI18n;
use \Twig\Environment as TwigEnvironment;
use \Twig\Loader\FilesystemLoader as TwigLoaderFilesystem;

$dataDir = __DIR__ . '/locale/';
$moReader = new MoReader(
['localeDir' => $dataDir]
);
$moReader->readFile($dataDir . 'fr.mo'); // Load the file you want (a specific language for example)
// Load the translation plugin
Launcher::setPlugin($moReader);

$loader = new TwigLoaderFilesystem([ __DIR__ . '/templates/' ]); // Load all templates from the dir
$twig = new TwigEnvironment($loader);

$twig->addExtension(new ExtensionI18n());
echo $twig->render(
'homepage.twig', // Can be found in the templates directory
[
'keyForTwig' => 'theValue', // Just an example line ;)
'say' => 'Hello world'
]
);
```

### Scripts

This package includes some scripts that can be usefull [scripts/tools](scripts/tools)
Expand Down

0 comments on commit b134cd9

Please sign in to comment.