2017 © Pedro Peláez
 

library gettexttranslator

Translator for Nette (PHP framework).

image

salamek/gettexttranslator

Translator for Nette (PHP framework).

  • Monday, February 26, 2018
  • by Salamek
  • Repository
  • 1 Watchers
  • 1 Stars
  • 7,888 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 8 Versions
  • 6 % Grown

The README.md

Gettext Translator

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., (*1)

Tested with nette 2.1>, please report any bugs into Issues, (*2)

Installation and usage

Installation via composer:

{
  "require":{
    "salamek/gettexttranslator"
  }
}

Usage

Set up config.neon:

common:
  gettextTranslator:
    lang: cs #default language
    files:
      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

extensions:
  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();
    } 
    else 
    {
       $this->translator->setLang($this->lang);
    }

    $template->setTranslator($this->translator);

    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

{_"Login"}

{_"piece", $number}
1 piece 
2 pieces 
5 pieces 

In forms

protected function createComponentMyForm()
{
  $form = new Form;
  $form->setTranslator($this->translator);

  // ...

  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>
  {_$flash->message|noescape}
</div>

Authors

Actively developing

  • Adam Schubert

Previously developed by

  • Josef Kufner (jk@frozen-doe.net)
  • Miroslav Paulík (https://github.com/castamir)
  • Roman Sklenář (http://romansklenar.cz)
  • Miroslav Smetana
  • Jan Smitka
  • Patrik Votoček (patrik@votocek.cz)
  • Tomáš Votruba (tomas.vot@gmail.com)
  • Václav Vrbka (gmvasek@php-info.cz)

Under New BSD License, (*3)

The Versions

26/02 2018

dev-master

9999999-dev https://github.com/Salamek/gettexttranslator

Translator for Nette (PHP framework).

  Sources   Download

BSD-3-Clause

The Requires

 

translator nette gettext

26/02 2018

v1.4.2

1.4.2.0 https://github.com/Salamek/gettexttranslator

Translator for Nette (PHP framework).

  Sources   Download

BSD-3-Clause

The Requires

 

translator nette gettext

07/01 2018

v1.4.1

1.4.1.0 https://github.com/Salamek/gettexttranslator

Translator for Nette (PHP framework).

  Sources   Download

BSD-3-Clause

The Requires

 

translator nette gettext

18/01 2017

v1.4

1.4.0.0 https://github.com/Salamek/gettexttranslator

Translator for Nette (PHP framework).

  Sources   Download

BSD-3-Clause

The Requires

 

translator nette gettext

02/01 2017

v1.3

1.3.0.0 https://github.com/Salamek/gettexttranslator

Translator for Nette (PHP framework).

  Sources   Download

BSD-3-Clause

The Requires

 

translator nette gettext

16/06 2015

v1.2

1.2.0.0 https://github.com/Salamek/gettexttranslator

Translator for Nette (PHP framework).

  Sources   Download

BSD-3-Clause

The Requires

 

translator nette gettext

19/11 2014

v1.1

1.1.0.0 https://github.com/Salamek/gettexttranslator

Translator for Nette (PHP framework).

  Sources   Download

BSD-3-Clause

The Requires

 

translator nette gettext

11/06 2014

v1.0

1.0.0.0 https://github.com/Salamek/gettexttranslator

Translator for Nette (PHP framework).

  Sources   Download

BSD-3-Clause

The Requires

 

translator nette gettext