PHP code example of cooperaj / better-twig-i18n

1. Go to this page and download the library: Download cooperaj/better-twig-i18n 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/ */

    

cooperaj / better-twig-i18n example snippets


/** @var $translator \Acpr\I18n\Translator **/
$pluralApples = $translator->translate(
    '%name% has %count% apple',
    [
        '%name' => 'Adam'
    ],
    'errors',
    'Some context to the translation',
    '%name% has %count% apples',
    5
);

// Assuming no translations had been loaded
// $pluralApples == 'Adam has 5 apples'

   // This will *not* work
   $var = 'I have an apple';
   $value = $translator->translate($var);
   
   // This will
   $value = $translator->translate('I have an apple');
   
shell
$ cp scripts/v3_po_update.php folder/containing/po.files
$ cd folder/containing/po.files
# edit script as appropriate for your translation domains
$ php v3_po_update.php