PHP code example of abbadon1334 / atk4-i18next-php
1. Go to this page and download the library: Download abbadon1334/atk4-i18next-php 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/ */
abbadon1334 / atk4-i18next-php example snippets
interface TranslatorInterface
{
/**
* Translates the given message.
*
* @param string $key
* @param array|null $parameters Array of parameters used to translate message
* @param string|null $context
* @param string|null $locale The locale or null to use the default
*
* @return string The translated string
*/
public function _(string $key, ?array $parameters = null, ?string $context = null, ?string $locale = null): string;
}
// Usage
$result = $this->translator->_('definitionKey');
$result = $this->translator->_('definitionKey', ['param1' => 'test']);
$result = $this->translator->_('definitionKey', ['param1' => 'test'], 'context');
$result = $this->translator->_('definitionKey', ['param1' => 'test'], 'context', 'specificLanguage');
$result = $this->translator->_('namespace:definitionKey', ['param1' => 'test'], 'context', 'specificLanguage');
$this->translator = new Translator();
$this->translator->setTranslationsPath(__DIR__.'/data/locales');