This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Translator for Nette (PHP framework).

v1.2.2 2016-12-09 14:55 UTC

This package is not auto-updated.

Last update: 2021-11-22 00:42:56 UTC


Gettext Translator is tool that enables simple and user friendly translation of your texts via panel in debug bar. No need to edit or operate with .po/.mo files.

Tested with nette 2.1>, please report any bugs into Issues

Installation and usage

Installation via composer:



Set up config.neon:

    lang: cs #default language
      front: %appDir%/lang # for module Front and other non-specified modules
      admin: %appDir%/lang-admin # for module Admin
    # optional with defaults
    layout: horizontal # or: vertical
    height: 450

  gettextTranslator: GettextTranslator\DI\Extension

Set up in BasePresenter.php

class BasePresenter extends Nette\Application\UI\Presenter
  /** @persistent */
  public $lang;

  /** @var \GettextTranslator\Gettext */
  protected $translator;

   * @param \GettextTranslator\Gettext
  public function injectTranslator(GettextTranslator\Gettext $translator)
    $this->translator = $translator;

  public function createTemplate($class = NULL)
    $template = parent::createTemplate($class);

    // if not set, the default language will be used
    if (!isset($this->lang)) 
      $this->lang = $this->translator->getLang();


    return $template;

Change language eg. in @template.latte

Choose language:
<a n:href="this, lang => en">English</a>
<a n:href="this, lang => cs">Česky</a>

How to translate a string

In template


{_"piece", $number}
1 piece <!-- $number = 1; -->
2 pieces <!-- $number = 2; -->
5 pieces <!-- $number = 5; -->

In forms

protected function createComponentMyForm()
  $form = new Form;

  // ...

  return $form;

In components

public function createTemplate($class = NULL)
  $template = parent::createTemplate($class);
  $template->setTranslator($this->parent->translator); // $translator in presenter has to be public
  // or $this->translator via construct/inject

  return $template;

In flash message

<div n:foreach="$flashes AS $flash" class="alert {$flash->type} fade in">
  <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>


Actively developing

  • Adam Schubert

Previously developed by

Under New BSD License