Skip to content

PHP library/api to provide Internationalisation and Localisation

License

Notifications You must be signed in to change notification settings

wdes/php-I18n-L10n

Folders and files

NameName
Last commit message
Last commit date

Latest commit

fcb7e79 · Mar 24, 2021
Mar 21, 2021
Mar 21, 2021
Mar 21, 2021
Mar 21, 2021
Mar 21, 2021
Mar 29, 2020
Dec 1, 2020
Jun 8, 2019
Mar 24, 2021
Jun 15, 2018
Mar 21, 2021
Dec 1, 2020
Mar 24, 2021
Mar 21, 2021
Dec 1, 2020
Mar 29, 2020

Repository files navigation

php-I18n-L10n

PHP library/api to provide Internationalisation and Localisation

Codacy Badge Lint and analyse files Run phpunit tests codecov FOSSA Status HitCount Packagist Latest Stable Version

License

FOSSA Status

About

We use the phpmyadmin/twig-i18n-extension for the Twig extension.

How to use

composer require wdes/php-i18n-l10n

Have a look at example file example/simple.php

Example

<?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 Here is an example to use them : scripts/update-example.sh