2017 © Pedro Peláez
 

library slim-twig-translation

Twig function for Illuminate\Translation\Translator in Slim framework

image

abedmaatalla/slim-twig-translation

Twig function for Illuminate\Translation\Translator in Slim framework

  • Friday, November 25, 2016
  • by abedmaatalla
  • Repository
  • 0 Watchers
  • 2 Stars
  • 109 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 2 Versions
  • 16 % Grown

The README.md

Slim Twig Translation

This repository provides a twig extension class for the twig view parser. The class adds a translate helper function for the use in twig templates. The translator function tries to call the trans() function of an Illuminate\Translation\Translator object in the slim DI container., (*1)

How to install

using Composer

Create a composer.json file in your project root:, (*2)

{
    "require": {
        "abedmaatalla/slim-twig-translation": "1.0.0"
    }
}

Then run the following composer command:, (*3)

$ php composer.phar install

How to use

Create new folder for langauges, (*4)

+ -- lang + -- en + -- file.php + -- fr + -- file.php, (*5)

Tanslator

Set up your Tansloator, (*6)

$container['translator'] = function ($c)
{
  // Register the English translator 'en'
  $translator = new Illuminate\Translation\Translator(new Illuminate\Translation\FileLoader(new Illuminate\Filesystem\Filesystem(), __DIR__ . '/lang'), 'en');
    // setLocal for new location 
    $translator->setLocale('fr');
    return $translator;
};

Slim

Set up your twig views as described in the SlimViews Repository. Add the extension to your parser extensions., (*7)

$container['view'] = function ($c)
{
  $view = new \Slim\Views\Twig('../resources/views');

  // add translator functions to Twig
  $view->addExtension(new \abedmaatalla\Slim\Twig\Extension\TranslationExtension($c->translator));

}

Twig template

In your twig template you would write:, (*8)

  {{ translate('male') }}

You can also use the shorthand:, (*9)

  {{ tans('male') }}

You can also use the shorthand:, (*10)

  {{ _('male') }}

The Versions

25/11 2016

dev-master

9999999-dev http://github.com/abedmaatalla/slim-twig-translation

Twig function for Illuminate\Translation\Translator in Slim framework

  Sources   Download

MIT

The Requires

 

by Abed MAATALLA

twig translation slim translate microframework illuminate

25/11 2016

1.0.0

1.0.0.0 http://github.com/abedmaatalla/slim-twig-translation

Twig function for Illuminate\Translation\Translator in Slim framework

  Sources   Download

MIT

The Requires

 

by Abed MAATALLA

twig translation slim microframework illuminate