1. Go to this page and download the library: Download charcoal/translator 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/ */
charcoal / translator example snippets
// Get a translation object from the Translator
$translation = $container['translator']->translation([
'en' => 'Hello World',
'fr' => 'Bonjour'
]);
// If cast to string, the default language will be used.
echo $translation;
// Use ArrayAccess to get (or set) a translated value.
echo $translation['fr'];
$translation['fr'] => 'Bonjour le monde';
// To loop through all translations:
foreach ($translation->data() as $lang => $translatedValue) {
// ...
}
use Charcoal\Translator\Middleware\LanguageMiddleware;
use Slim\App;
$app = new App();
// Register middleware
$app->add(new LanguageMiddleware([
'default_language' => 'fr',
'use_params' => true,
'param_key' => 'hl',
]));