Skip to content

flame-org/Translator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 

Repository files navigation

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

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.

Actual info/manual: http://wiki.nette.org/cs/cookbook/zprovozneni-prekladace-nettetranslator

1. Enable Translator

config.neon:

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

2. Use in templates

default.latte:

{_"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;
	}

}

About

Nette translator for multilanguage applications

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 53.8%
  • HTML 46.2%