PHP code example of dasred / translation

1. Go to this page and download the library: Download dasred/translation 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/ */

    

dasred / translation example snippets



return [
    'name' => 'Name',
    'hello' => 'Hallo',
    'world' => 'Welt'
];


return [
    'name' => 'name',
    'hello' => 'hello',
    'world' => 'world'
];

$translator = new \DasRed\Translation\Translator('de_DE', __DIR__ . '/translations', 'en_GB');
echo $translator->__('general.hello'); // echos "Hallo"
echo $translator->__('general.hello', [], 'en_GB'); // echos "hello"
echo $translator->__('general.hello', [], 'fr_FR'); // echos "hello" from en_GB


return [
    'name' => 'name',
    'hello' => 'hello',
    'world' => 'world',
    'seconds' => '[SECONDS] seconds',
    'secondsAbbr' => '[SECONDS]s',
];

$translator = new \DasRed\Translation\Translator('en_GB', __DIR__ . '/translations', 'en_GB');
echo $translator->__('general.seconds'); // echos "[SECONDS] seconds"
echo $translator->__('general.seconds', ['seconds' => 10]); // echos "10 seconds"
echo $translator->__('general.secondsAbbr', ['seconds' => 10]); // echos "10s"
echo $translator->__('general.secondsAbbr', ['seconds' => number_format(10.00020200202, 2, '.', ',')]); // echos "10.00s"


return [
    'name' => 'name',
    'hello' => 'hello',
    'world' => 'world',
    'seconds' => '[b][SECONDS][/b] seconds',
    'secondsAbbr' => '[b][SECONDS][/b]s',
];

$translator = new \DasRed\Translation\Translator('en_GB', __DIR__ . '/translations', 'en_GB', null, new \DasRed\Parser\BBCode());
echo $translator->__('general.seconds'); // echos "<strong>[SECONDS]</strong> seconds"
echo $translator->__('general.seconds', ['seconds' => 10]); // echos "<strong>10</strong> seconds"
echo $translator->__('general.secondsAbbr', ['seconds' => 10]); // echos "<strong>10</strong>s"
echo $translator->__('general.secondsAbbr', ['seconds' => number_format(10.00020200202, 2, '.', ',')]); // echos "<strong>10.00</strong>s"
text
given translation directory
|--- de_DE
       |--- general.php
       |--- account.php
       |--- other.php
|--- en_GB
       |--- general.php
       |--- account.php
       |--- other.php