PHP code example of michaelspiss / translation

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

    

michaelspiss / translation example snippets




use MichaelSpiss\Translation\Translator;

$translator = new Translator('en', 'path/to/translations');

$translator->trans('message.hello_world');



return [
    'hello_world' => 'Hello World!'
];

$translator->setLocale('de');

$translator->trans('message.hello_world', [], 'de');
// or:
$translator->transChoice('message.choice', 1, [], 'de');



return [
    'with_placeholder' => 'Hello {placeholder}!'
];

$translator->trans('message.with_placeholder', ['placeholder' => 'World']);
// returns "Hello World!"



return [
    'simple_pluralization' => 'Dog | Dogs'
];



return [
    'advanced_pluralization' => '{0} None | [1,10] Some | [11,*] Many'
];

$translator->transChoice('message.simple_pluralization', 4);
// returns "Dogs"

$translator->transChoice('message.advanced_pluralization', 8);
// returns "Some"

translations/
 |- en/
 |   |- message.php
 |- de/
 |- fr/