heldercervantes Posted June 7, 2021 Share Posted June 7, 2021 Hello guys and gals. First time I've done this, took a site that started from the blank template and added language support. Everything's working except when I try to add translatable strings to my templates. I'm getting a `Call to undefined function __()`. No idea what I need to do. Can someone help? Thanks in advance. H Link to comment Share on other sites More sharing options...
wbmnfktr Posted June 8, 2021 Share Posted June 8, 2021 Is each and every language module installed? Languages Support LanguageSupportFields LanguageSupportPageNames LanguageTabs Just did this in a clean blank installation, added a second language, and added this to one of the templates: <?php echo __("This is my translatable phrase."); ?> No issues at all. When I remember correctly there were issues in the past with some PHP versions but thats long ago. Another thing could be a missing namespace declaration. Or... try to copy parts of the multilanguage site profile over. https://github.com/processwire/processwire/tree/master/site-languages/templates The docs:https://processwire.com/docs/multi-language-support/code-i18n/ 1 Link to comment Share on other sites More sharing options...
heldercervantes Posted June 8, 2021 Author Share Posted June 8, 2021 @wbmnfktr Strange. If I do that on a template file directly, it works fine. But if I put it in a file that's included, it breaks. WTH? ? Also, I just tested on another site that I'm working on and it works there. Both projects were setup the same way, in fact, the one that has this issue started from the other (basic setup with a docker-compose that sets up a container running the PW installer). Environment is exactly the same and the only difference I can see is that in the other one I selected the languages profile on install. Link to comment Share on other sites More sharing options...
wbmnfktr Posted June 8, 2021 Share Posted June 8, 2021 There must be missing a module or something. This is totally weird. Just tested it with includes and such. Works perfectly well. Link to comment Share on other sites More sharing options...
heldercervantes Posted June 8, 2021 Author Share Posted June 8, 2021 @wbmnfktr It gets weirder ? So here, $b->blockType is a php file name. In that file, the first line is echoing a __() string. I'd really love to understand why it works in the first include and not in the second. It's right up there among the weirdest things in the history of weirdness. Anyways, I'm just glad I have a workaround. Thanks for your time ? Link to comment Share on other sites More sharing options...
wbmnfktr Posted June 8, 2021 Share Posted June 8, 2021 What happens when you switch those around? Will the second one always fail? Link to comment Share on other sites More sharing options...
Robin S Posted June 8, 2021 Share Posted June 8, 2021 It sounds like it might be a namespace issue. Check that your template files and included files start with: <?php namespace ProcessWire; FileCompiler tries to automatically fix files that don't declare the PW namespace but I think the most reliable approach is to always add it yourself. 1 Link to comment Share on other sites More sharing options...
heldercervantes Posted June 9, 2021 Author Share Posted June 9, 2021 @wbmnfktr Switching them around does the same thing@Robin S Adding namespace makes it worse, with that even the workaround doesn't work ? Well at least for now I managed to get it working. I'm just afraid that the whole thing crumbles and I have to setup everything in the cms from scratch. I've never backed up my DB so frequently as I'm doing now ? 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