GithubHelp home page GithubHelp logo

translator's Introduction

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;
	}

}

translator's People

Contributors

tomasvotruba avatar jsifalda avatar martenb avatar

Watchers

James Cloos avatar  avatar

Forkers

martenb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.