PHP code example of locomotivemtl / charcoal-translator
1. Go to this page and download the library: Download locomotivemtl/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/ */
locomotivemtl / charcoal-translator example snippets
$container->register(new \Charcoal\Translator\ServiceProvider\TranslatorServiceProvider());
$container['translator/config'] = new \Charcoal\Translator\TranslatorConfig([
// …
]);
$container['locales/config'] = new \Charcoal\Translator\LocalesConfig([
// …
]);
// 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) {
// ...
}