2017 © Pedro PelĆ”ez
 

library gettext-latte

Gettext translator for Latte template

image

h4kuna/gettext-latte

Gettext translator for Latte template

  • Saturday, January 28, 2017
  • by h4kuna
  • Repository
  • 1 Watchers
  • 13 Stars
  • 4,029 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 9 Open issues
  • 22 Versions
  • 3 % Grown

The README.md

[Abandoned]

GettextLatte

Build Status Latest stable, (*1)

is localization addon for Nette framework 2.3, which natively supports gettext., (*2)

Conditions for start-up

  • gettext extension enabled
  • language installed on server, you can check by using command $ locale -a
  • your application written in UTF-8 encoding

In the repository is directory locale containing prepared directory structure for your project. In folder example are files, whose help you setup this translator. You can write your application in your native language, here is example in english, but it may be czech, slovak, german language..., (*3)

Start-up

Clone this repository or use composer., (*4)

composer require h4kuna/gettext-latte

Router keep language., (*5)

/**
 * @return Nette\Application\IRouter
 */
public static function createRouter(\h4kuna\Gettext\GettextSetup $translator) {
    $router = new RouteList();
    $router[] = new Route('index.php', 'Homepage:default', Route::ONE_WAY);
    $router[] = new Route('[<lang ' . $translator->routerAccept() . '>/]<presenter>/<action>/[<id>/]', array(
        'presenter' => 'Homepage',
        'action' => 'default',
        'lang' => $translator->getDefault()
    ));

    return $router;
}

examples/config.neon

On Mac encoding is represented as 'en_US.UTF-8' everytime dojo format 'en_US.utf8'., (*6)

extensions:
    gettextLatteExtension: h4kuna\Gettext\DI\GettextLatteExtension

gettextLatteExtension:
    langs:
        cs: cs_CZ.utf8
        sk: sk_SK.utf8
        en: en_US.utf8

Install new macro to latte engine with alias for native gettext function {_'' /*, ...*/} and {_n'', '', '' /*, ...*/} new is {_d'catalog', 'message'} and plural {_dn'catalog', 'message' /*, ...*/}., (*7)

Run service and support automatic detection of language

Load language as soon as possible., (*8)

<?php
use Nette\Application\UI\Presenter;

abstract class BasePresenter extends Presenter {

    /** @persistent */
    public $lang;

    /** @var \h4kuna\Gettext\GettextSetup */
    protected $translator;

    /**
     * Inject translator
     * @param \h4kuna\Gettext\GettextSetup
     */
    public function injectTranslator(\h4kuna\Gettext\GettextSetup $translator) {
        $this->translator = $translator;
    }

    protected function startup() {
        parent::startup();
        $this->lang = $this->translator->setLanguage($this->lang);
    }

    /**
     * Or PHP 5.4+ ****************************************************************
     * *************************************************************************
     */
    use \h4kuna\Gettext\InjectTranslator;
}

After install translator please empty temp directory, otherwise you may get "Call to undefined method Nette\Templating\FileTemplate::translate()"., (*9)

How to write texts in PHP files

Outside the template using gettext., (*10)

<?php
echo gettext('Hi'); //or alias _
echo _('Hi');
echo ngettext('dog', 'dogs', 2);

echo sprintf(_('%s possible %s %s'), 'another', 'optional', 'params');

In template using macros. Number of parameters isn't limited. Function sprintf is automatically added. Look at examples/example.latte, (*11)

macro in template translate to php
{_'Hi'} echo gettext('Hi');
{_'Today is %s', $date} echo sprintf(gettext('Today is %s'), $date);
In the previous version, the inflection was written like this.
{_n'dog', 'dogs', $count} echo ngettext('dog', 'dogs', $count);
Now it's off and is written following way.* (It is possible to turn on with third parameter in constructor.)
{_n'dog', $count} echo ngettext('dog', 'dog', $count);
{_n'%s dog has email %s', $count, $email} echo sprintf(ngettext('%s dog has email %s', '%s dog has email %s', $count), $count, $email);
If you need to decline to negative, variable must contain abs.
{_n'today is %s degree temperature', $absTemperature} echo sprintf(ngettext('today is %s degree temperature', 'today is %s degree temperature', abs($absTemperature)), $absTemperature);
If you have many variables and replace the first variable not governed translation variable must contain plural.
{_n'Name: %s, age: %s year old', $name, $pluralYear} echo sprintf(ngettext('Name: %s, age: %s year old', 'Name: %s, age: %s year old', $pluralYear), $name, $pluralYear);

* It was changed, because inflection is defined in catalog everytime, for language whose has more than 2 level inflection., (*12)

Let's start translate

Download PoEdit. Before each Poedit run you must have all templates compiled to php in temp directory, for this is use script like examples/latte-compiler., (*13)

Open the .po file. Setup directory search - by default it is temp/cache/latte and app and click "update catalog", after update catalog you don't need restart apache., (*14)

If you write application in language with three inflection levels instead of two, for example czech, you must have catalog with translation czech to czech but only for plural., (*15)

Downloadable catalog

For your translators you provide catalog for download., (*16)

$this->translator->download('cs'); //Offers catalog download

Run Tests

Composer must be instaled. And than you execute only script., (*17)

./tests/run-tests.sh

The Versions

15/09 2013

v1.2.2

1.2.2.0 https://github.com/h4kuna/gettext-latte

Gettext translator for Latte template

  Sources   Download

MIT

The Requires

 

The Development Requires

by Milan Matějček

22/05 2013

v1.2.1

1.2.1.0 https://github.com/h4kuna/gettext-latte

Gettext translator for Latte template

  Sources   Download

MIT

The Requires

 

by Milan Matějček

04/04 2013

dev-gui

dev-gui https://github.com/h4kuna/gettext-latte

Gettext translator for Latte template

  Sources   Download

MIT

The Requires

 

by Milan Matějček

translator latte gettext

02/03 2013

v1.2.0

1.2.0.0 https://github.com/h4kuna/gettext-latte

Gettext translator for Latte template

  Sources   Download

MIT

The Requires

 

by Milan Matějček

13/02 2013

v1.1.0

1.1.0.0 https://github.com/h4kuna/gettext-latte

Gettext translator for Latte template

  Sources   Download

MIT

The Requires

 

by Milan Matějček

10/02 2013

v1.0.13

1.0.13.0 https://github.com/h4kuna/gettext-latte

Gettext translator for Latte template

  Sources   Download

MIT

The Requires

 

by Milan Matějček

10/02 2013

v1.0.12

1.0.12.0 https://github.com/h4kuna/gettext-latte

Gettext translator for Latte template

  Sources   Download

MIT

The Requires

 

by Milan Matějček

08/02 2013

v1.0.11

1.0.11.0 https://github.com/h4kuna/gettext-latte

Gettext translator for Latte template

  Sources   Download

MIT

The Requires

 

by Milan Matějček

31/01 2013

v1.0.10

1.0.10.0 https://github.com/h4kuna/gettext-latte

Gettext translator for Latte template

  Sources   Download

MIT

The Requires

 

by Milan Matějček

17/01 2013

v1.0.9

1.0.9.0 https://github.com/h4kuna/gettext-latte

Gettext translator for Latte template

  Sources   Download

MIT

The Requires

 

by Milan Matějček

17/12 2012

v1.0.8

1.0.8.0 https://github.com/h4kuna/gettext-latte

Gettext translator for Latte template

  Sources   Download

MIT

The Requires

 

by Milan Matějček

27/10 2012

v1.0.7

1.0.7.0 https://github.com/h4kuna/gettext-latte

Gettext translator for Latte template

  Sources   Download

MIT

The Requires

 

by Milan Matějček

15/10 2012

v1.0.6

1.0.6.0 https://github.com/h4kuna/gettext-latte

Gettext translator for Latte template

  Sources   Download

MIT

The Requires

 

by Milan Matějček

14/10 2012

v1.0.5

1.0.5.0 https://github.com/h4kuna/gettext-latte

Gettext translator for Latte template

  Sources   Download

MIT

The Requires

 

by Milan Matějček

13/10 2012

v1.0.4

1.0.4.0 https://github.com/h4kuna/gettext-latte

Gettext translator for Latte template

  Sources   Download

MIT

The Requires

 

by Milan Matějček

12/10 2012

v1.0.3

1.0.3.0 https://github.com/h4kuna/gettext-latte

Gettext translator for Latte template

  Sources   Download

MIT

The Requires

 

by Milan Matějček