tpr Posted June 26, 2015 Share Posted June 26, 2015 I have installed these modules to get Twig support on a multilanguage site: Template Twig Replace (Template Twig Replace Language Support) ProcessLanguageTranslatorTwigSupport Everything went fine until I tried to use "__" functions, eg. {{ __('my_string') }} The string showed up in the Language translator inside PW and I could translate it. However, I couldn't display it on the site. What am I missing? Ps. I was able to access these translations with plain PHP and with another templating system. Link to comment Share on other sites More sharing options...
alemachado Posted July 16, 2015 Share Posted July 16, 2015 Hi tprI've just passed through the same problem. The solution is to give the location/name of your twig file as the second parameter. Ex: {{ __('my_string', 'home') }} for templates/home.twig or {{ __('my_string', 'includes/header') }} for templates/includes/header.twig 2 Link to comment Share on other sites More sharing options...
tpr Posted July 16, 2015 Author Share Posted July 16, 2015 Thanks, I will check that next time. Now I'm using Latte and made a handy translation helper function that adds the file path (= textdomain in PW, as I learned) as the second parameter automatically (just like what you suggested). Doing so I can have all custom string translations in one file (_strings.php). Link to comment Share on other sites More sharing options...
justb3a Posted July 17, 2015 Share Posted July 17, 2015 Sometimes it's actually helpful to read the usage instructions. If you have an idea how to avoid passing a second parameter (=textdomain), please let me know. Link to comment Share on other sites More sharing options...
tpr Posted July 17, 2015 Author Share Posted July 17, 2015 I could get twig files into the admin translator but I couldn't echo them. I'm not sure whether I tried adding the path as the second parameter but probably not. Unfortunately I can't check this now because I'm using another template engine. What I do now is a simple function - optional context/textdomain get their default values in the function if not set: t('String to translate', 'optional context', 'optional textdomain') This works fine but because it doesn't contain "__" it won't appear in the admin translator. It' a nuissance because I have to manually list them in my _strings.php file, but for me it's better than having to edit strings in several files. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now