PHP code example of impulsephp / translation

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

    

impulsephp / translation example snippets




return [
    'hello' => 'Bonjour',
    'welcome' => 'Bienvenue {name}',
];

use Impulse\Translation\Translator;

$translator = new Translator('fr');

echo $translator->trans('messages.hello');
echo $translator->trans('messages.welcome', ['name' => 'Guillaume']);

$translator->setLocale('en');
echo $translator->trans('messages.hello');

$translator->addNamespace('ui', '/chemin/vers/un/package/translations');

echo $translator->trans('ui::ui.select.search_placeholder');

use Impulse\Translation\Contract\TranslatorInterface;

$translator = $container->get(TranslatorInterface::class);
text
translations/
├── en/
│   └── messages.php
└── fr/
    └── messages.php