Jump to content

Blank template to language support: undefined function __()


heldercervantes
 Share

Recommended Posts

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

Is each and every language module installed?

  1. Languages Support
  2. LanguageSupportFields
  3. LanguageSupportPageNames
  4. 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."); ?>

2021-06-08_15-14.thumb.png.3715e41391c3da56300e29d9e801ed3e.png

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/

 

 

  • Like 1
Link to comment
Share on other sites

@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

@wbmnfktr It gets weirder ?

image.png.6dbdec7f573e50def77bf3f2c0abf23b.png

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

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. 

  • Thanks 1
Link to comment
Share on other sites

@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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...