2017 © Pedro Peláez
 

library twig-translation-extension

Twig translate function for Illuminate\Translation\Translator.

image

rafaph/twig-translation-extension

Twig translate function for Illuminate\Translation\Translator.

  • Tuesday, March 15, 2016
  • by rafaph
  • Repository
  • 1 Watchers
  • 2 Stars
  • 153 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 25 % Grown

The README.md

Twig Translation Extension

Translation functions for Twig provide by Illuminate/translation., (*1)

Installation

composer require rafaph/twig-translation-extension

Usage

  • Configure the Illuminate\Translation\Translator:
$langPath = __DIR__ . '/lang';
$locale = 'pt';

$translator = new \Illuminate\Translation\Translator(
    new \Illuminate\Translation\FileLoader(
        new \Illuminate\Filesystem\Filesystem(),
        $langPath
    ),
    $locale
);
$translator->setFallback('en');

More details about the configurations of the Translator package you can find in the Laravel docs., (*2)

  • Add Twig extension
// ...
$twig->addExtension(
    new \Raph\Twig\Extension\TranslationExtension($translator)
);
  • Configure your messages
//in lang/en/messages.php

return [
    'hello' => 'Hello :name!',
    'there' => '{0} There are none|[1,19] There are some|[20,Inf] There are many'
];
//in lang/pt/messages.php

return [
    'hello' => 'Olá :name!',
    'there' => '{0} Nenhum|[1,19] Alguns|[20,Inf] Muitos'
];
  • Use in templates
<h2>{{ trans('messages.hello', {'name': 'Jane Doe'}) }}</h2>
<h2>{{ trans_choice('messages.there', 2) }}</h2>

The Versions

15/03 2016

dev-master

9999999-dev https://github.com/rafaph/twig-translation-extension#README

Twig translate function for Illuminate\Translation\Translator.

  Sources   Download

MIT

The Requires

 

by Raphael Castro

twig localization translate

15/03 2016

1.0.0

1.0.0.0 https://github.com/rafaph/twig-translation-extension#README

Twig translate function for Illuminate\Translation\Translator.

  Sources   Download

MIT

The Requires

 

by Raphael Castro

twig localization translate