dev-master
9999999-devTwig Translation Extension using YAML files
The Requires
- php >=5.3.0
- twig/twig ~1.0
- symfony/yaml ^2.6
Twig Translation Extension using YAML files
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
This project has been archived because is old and has vulnerabilities, (*10)
Twig Translation Extension using YAML files