2017 © Pedro Peláez
 

library translator

Nette translator for multilanguage applications

image

flame/translator

Nette translator for multilanguage applications

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 37 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Nette Translator (c) Patrik Votoček (Vrtak-CZ), 2010 (http://patrik.votocek.cz), (*1)

Note

This is short manual how to use Nette Translator in the newest Nette 2.0 in its most simple version. No need to edit or operate with .po/.mo files required. Written 2012-02-10., (*2)

Actual info/manual: http://wiki.nette.org/cs/cookbook/zprovozneni-prekladace-nettetranslator, (*3)

1. Enable Translator

config.neon:, (*4)

common:
    services:
        translator:
            factory: \Flame\Translator\Gettext::getTranslator
            setup:
                - addFile(%appDir%/lang, front) # at leas one file required
                - \Flame\Translator\Panel::register # panel to debug bar

NOTE: Do not forget to make folder %appDir%/lang writable, (*5)

2. Use in templates

default.latte:, (*6)

{_"Dog"}
{_"Cat", $number} // for plural, default are Czech plurals: 1, 2-4, 5+

3. Use in forms

/**
 * Base presenter for all application presenters.
 */
abstract class BasePresenter extends Flame\Application\UI\Presenter
{

    /**
     * @persistent
     */
    public $lang;

    /**
     * @autowire
     * @var \Flame\Translator\Gettext
     */
    protected $translator;

    /**
     * @autowire
     * @var \Nette\Http\Request
     */
    protected $request;

    protected function startup()
    {
        parent::startup();

        if (!$this->lang) {
            $lang = $this->request->detectLanguage(array('en', 'cs')) ?: 'cs';
            $this->redirectUrl($lang);
        }

    }

    public function createTemplate($class = NULL)
    {
        $template = parent::createTemplate($class);
        $this->translator->setLang($this->lang); // set lang
        $template->setTranslator($this->translator);
        return $template;
    }

}

The Versions

08/03 2017

dev-master

9999999-dev https://github.com/flame-org/Translator

Nette translator for multilanguage applications

  Sources   Download

BSD-2-Clause-FreeBSD

The Requires

 

translator simple multilanguage nette tools flame