PHP code example of smmoosavi / twig-php-gettext

1. Go to this page and download the library: Download smmoosavi/twig-php-gettext library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

smmoosavi / twig-php-gettext example snippets


$twig->addExtension(new smmoosavi\util\twiggettext\Extension_L10n());

 // test.php
l\gettext\L10n;
// initializing php-gettext
$locale = 'fa_IR';
$lang = 'fa';
L10n::init($lang, __DIR__ . "/locale/$locale/LC_MESSAGES/messages.mo");

// simple using of php-gettext
echo __('Hi')."\n";

// initializing twig
$loader = new Twig_Loader_String();
$twig = new Twig_Environment($loader);

// initializing twig-php-gettext
$twig->addExtension(new smmoosavi\util\twiggettext\Extension_L10n());

// using of twig-php-gettext
echo $twig->render("{{ __('Hi') }} {{ name }}<br>", array('name' => 'علی'));
json
{
    "mmoosavi/twig-php-gettext": "dev-master"
    }
}
bash
$ php composer.phar install