Usage
Translation
With Limpid translation never been easy.
First of all you need to open
if you have route like this
After that, under your module you just need to create a directory called
Then, to call these translated words in your views, Limpid provides you a twig extension called
Remember, Limpid is a friendly framework :p, of course you can do that you just need to create your links and in the
First of all you need to open
settings.php
in the configuration directory of Limpid then enable the translation service and choose your default language to be displayed;<?phpBy enabling the service, Limpid will add, automatically, the chosen language to your routes ex:
/** in the settings file framework\settings.php **/
return [
. . .
//-translator configuration
'translator' => [
'enabled' => false,
'default_lang' => 'fr',
], . . . ];
if you have route like this
/articles/my-article
will become like this /fr/articles/my-article
.After that, under your module you just need to create a directory called
Translator
with only one file in it called book.php
where this book will contain your words's translation to any language you choose. So the book will look like this:<?php return [ 'menu.accueil' => [//---key word 'fr' => 'Accueil',//---translation to french 'en' => 'Home',//--translation to english ], 'menu.products' => [ 'fr' => 'Nos Produits', 'en' => 'Our Products', ], 'menu.gallery' => [ 'fr' => 'Galerie', 'en' => 'Gallery', ], 'menu.contact' => [ 'fr' => 'Contactez-nous', 'en' => 'Contact us', ], ];As you can see this book will return an array with translated words.
Then, to call these translated words in your views, Limpid provides you a twig extension called
translate
that needs two parameters to work module's name
and key word
:{{ translate('HelloLimpid', 'menu.accueil') }}Limpid will search in the given module and get the translation book and get you the translated word that you asked for.
NB: If Limpid can't find the key word in the book he will simply display it as it is.Ok, this looks easy, but if I want to create links to change from french to english language for example how do I do that ?
Remember, Limpid is a friendly framework :p, of course you can do that you just need to create your links and in the
href
attribute just call Limpid's magic extension switch_lang
and give it the target language as parameter:<a href="{{ switch_lang('en') }}">English</a> <a href="{{ switch_lang('fr') }}">French</a>And let limpid do his work, he will take care of your routes and translation language.