2017 © Pedro PelĂĄez
 

library twig-translation

Twig Translation Extension using YAML files

image

vsalvans/twig-translation

Twig Translation Extension using YAML files

  • Sunday, July 26, 2015
  • by vsalvans
  • Repository
  • 1 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Translation Twig Extension

Twig Translation Extension using YAML files, (*1)

//TranslationTwigExtension is in include folder
$twig->addExtension(new TranslationTwigExtension($lang, __DIR__.'/locale'));

First argument is $lang and the second is the translation yaml files folder, (*2)

/locale/es.yaml is the translation file, (*3)

For instance in es.yaml, (*4)

Hello: Hola
<a href="#">English</a>: <a href="#">Spanish</a>
Your name is @name: Your name is @name

In the twig template use trans function like this:, (*5)

<h1>{{ "Hello" | trans }}</h1>
{{ "<a href=\"#\">English</a>" | trans | raw }} <!-- for translation of html content -->
<p>{{ "Your name is @name" | trans({"@name" : "vĂ­ctor"}) }}</p> <!-- for translation with tokens -->

You can add a language fallback usign the third parameter:, (*6)

$twig->addExtension(new TranslationTwigExtension($lang, __DIR__.'/locale', $fallbackLanguage));

If there is no translation for the current language it searchs a translation in the fallback language files, (*7)

You can add debug log file. It add a new entry for each translation failed, (*8)

$twig->addExtension(new TranslationTwigExtension($lang, __DIR__.'/locale', $fallbackLanguage, $logfile));

Then in the terminal you can list all strings without translation buy typing:, (*9)

$ cat log_file | sort -u

Alert!!

This project has been archived because is old and has vulnerabilities, (*10)

The Versions

26/07 2015

dev-master

9999999-dev

Twig Translation Extension using YAML files

  Sources   Download

The Requires