composer require kdyby/translation

Troll Hammaren@SKEEVE MINGW64 /c/home/sablona (master)
$ composer require kdyby/translation
Using version ^2.4 for kdyby/translation
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 4 installs, 0 updates, 0 removals
- Installing symfony/filesystem (v3.3.11) Downloading: 100%
- Installing symfony/config (v3.3.11) Downloading: 100%
- Installing symfony/translation (v3.3.11) Downloading: 100%
- Installing kdyby/translation (v2.4.0) Loading from cache
symfony/config suggests installing symfony/yaml (To use the yaml reference dumper)
symfony/translation suggests installing symfony/yaml ()
kdyby/translation suggests installing kdyby/monolog (Integration of Monolog into Nette Framework.)
kdyby/translation suggests installing symfony/locale (Locale component provides fallback code to handle cases when the intl extension is missing.)
kdyby/translation suggests installing symfony/yaml (If you wanna store translations in YAML format - supports multiline strings.)
Writing lock file
Generating autoload files

Troll Hammaren@SKEEVE MINGW64 /c/home/sablona (master)

Konfigurace

app/config/config.neon

extensions:
translation: Kdyby\Translation\DI\TranslationExtension

app/router/RouterFactory.php

namespace App;

use Nette;
use Nette\Application\Routers\Route;
use Nette\Application\Routers\RouteList;

class RouterFactory
{
use Nette\StaticClass;
/**
* @return Nette\Application\IRouter
*/
public static function createRouter()
{
$router = new RouteList;
$router[] = new Route("[<locale=cs |en>/]<prtesenter>/<action>[/</id>]", "Homepage:default");
return $router;
}
}


app/presenters/ HomepagePresenter

namespace App\Presenters;

use Nette;
use App\Model;

class HomepagePresenter extends BasePresenter
{
/** @persistent */
public $locale;

/** @var \Kdyby\Translation\Translator @inject */
public $translator;

public function renderDefault()
{
}

}

Slovníky - app/lang

  • Formát Neon
  • app/lang /ui.cs_CZ.neon
title: Projekt ŠABLONA
  • app/lang /ui.en_US.neon
title: The project SABLONA

Použití v šabloně

<div class="hlavicka">
    <a n:href="default locale=>en">en</a>
    <a n:href="default locale=>cs">cs</a>
</div>

<div class="nadpis">{_ ui.title}</div>

 

 

Vlastimil Pošmura, 2020