2017 © Pedro Peláez
 

library lagan_translate

Twig function for Illuminate\Translation\Translator in Slim framework. Based on dkesberg/slim-twig-translation-extension

image

aureliopons/lagan_translate

Twig function for Illuminate\Translation\Translator in Slim framework. Based on dkesberg/slim-twig-translation-extension

  • Friday, August 18, 2017
  • by aureliopons
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Lagan Translation Extension

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)

Is an adaptation of dkesberg/slim-twig-translation-extension to Slim 3 framework., (*2)

Is intended to use with Lagan CMS (https://www.laganphp.com/), (*3)

How to install

using Composer

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

{
    "require": {
        "aureliopons/lagan_translate": "dev-master"
    }
}

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

$ php composer.phar install

How to use

Twig template

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

  {{ translate('male') }}

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

  {{ _('male') }}

Adding to Lagan

At public/index.php add, (*8)

$view->addExtension( new \Aureliopons\Slim\Twig\Extension\TranslationExtension() );

And use as a simple injection, using ROOT_PATH to reference 'lang' folder:, (*9)

use Illuminate\Translation\Translator;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Translation\FileLoader;

$translator = new Translator(new FileLoader(new Filesystem(), ROOT_PATH . '\lang'), 'en');
$translator->setFallback('en');
$app->translator = $translator;

Then you can create \lang\en folder with your translations array, (*10)

return array(
  'hello'    => 'Hello World!'  
);

Add new folders for different languages., (*11)

The Versions

18/08 2017

dev-master

9999999-dev http://github.com/aureliopons/lagan_translate

Twig function for Illuminate\Translation\Translator in Slim framework. Based on dkesberg/slim-twig-translation-extension

  Sources   Download

MIT

The Requires

 

by Aurelio Pons

twig translation slim illuminate lagan