1. Go to this page and download the library: Download elcheco/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/ */
elcheco / translator example snippets
use ElCheco\Translator\Translator;
class BasePresenter extends \Nette\Application\UI\Presenter
{
private Translator $translator;
public function injectTranslator(Translator $translator)
{
$this->translator = $translator;
}
public function beforeRender()
{
// Set translator for templates
$this->template->setTranslator($this->translator);
}
public function handleSwitchLocale(string $locale)
{
$this->translator->setLocale($locale);
$this->redirect('this');
}
}
use ElCheco\Translator\Cldr\CldrPluralRules;
// Get plural category for a number
$category = CldrPluralRules::getPluralCategory('cs_CZ', 1.5); // 'many'
// Get available categories for a locale
$categories = CldrPluralRules::getAvailableCategories('cs_CZ');
// ['one', 'few', 'many', 'other']
// Enable usage tracking
$factory = new DbDictionaryFactory($connection, 'Module', true);
// Later, save statistics
$dictionary->saveUsageStats();
// Query usage data
SELECT key, usage_count FROM translation_keys ORDER BY usage_count DESC;