Jump to content

Translations in includes not working


Inxentas
 Share

Recommended Posts

I do not seem to be able to properly display translated text when the call to translate, using either __() or $this->_(), is put into an include. In my template file I have this statement:

<?php include("inc/bku-block-footer.php"); ?>

No matter what I do, the untranslated text is displayed in the frontend. I have tried several things already:

  • Fiddled with $config->templateCompile = false in config.php as described here. Gave me additional options in the backend. None of these options seems to have any effect on the frontend.
  • Fiddled with textdomains like described here. To no avail.
  • Fiddled with template compilation in general, tried all options. No effects.
  • Tried adding the ProcessWire namespace to my template file. Again, no effect on translations.

It doesn't seem to matter, any call to the translation functions returns the untranslated, original value unless I place the call inside the template file. I must be missing something very obvious, anyone got an idea?

Link to comment
Share on other sites

This is my template file bku-news-page.php:

<?php
namespace ProcessWire;
?>
<!DOCTYPE html>
<html>
    <?php include("inc/head.php"); ?>
    <body>
    <?php include("inc/bku-block-topbar.php"); ?>
    <?php include("inc/bku-block-menu.php"); ?>
    <?php include("inc/bku-block-newsitems.php"); ?>
    <?php include("inc/bku-block-footer.php"); ?>
    </body>
</html>

This is the relevant snippet of code from the include:

<?php echo $this->_("Voor vragen of advies kunt u altijd contact met ons opnemen"); ?>

Off course that sentence has been translated by selecting the specific include under Languages. It does not work, but when I do exactly the same using the template file itself, it works smoothly.

Edited by Inxentas
Link to comment
Share on other sites

  • 2 years later...

This topic is a bit old already... but I have the same problem. Translated a string that appears in an include file (.inc), but the translated string is not showing up for the secondary language. I tried the above, but without success...

 

OK... I found the problem. It had nothing to do with the include file.
Instead of.  $this->_("xyz") as shown in the docs I only used .__("xyz"). That worked.

Edited by uliverse
Link to comment
Share on other sites

5 hours ago, uliverse said:

$this->_("xyz") as shown in the docs I only used .__("xyz"). That worked.

The former is for module context while the latter is for frontend template file context.

Can you point to the part of the docs you are referring to?

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...