Jump to content

String translation confusion


Recommended Posts

Hi,

We have been using string translations in our sites for a while. Usually without much of a problem. I did notice an inconsistency before in that sometimes we would have to use _("string") and at other times __("string"). Event though they were the same template (in other installations).

Now we have an installation, where no configuration works:

  • __("string")
    • Error in front-end
      • Call to undefined function __(), did you mean _()?
  • _("string")
    • In this case the translation is not detected.
    • No error in front-end
  • $this->_("string")
    • Translation is detected in the back-end
    • Front-End does not display the translation

Here some example codes.

From a working installation:

<p><span id="fzgVB"></span> <?php echo __("von"); ?> <span id="fzgTotal"></span> </p>

From the broken installation with the above issues:

<p><span id="fzgVB"></span> <?php echo $this->_("von"); ?> <span id="fzgTotal"></span> </p>

This is the translation file:

{
    "file": "site\/templates\/webKitLagerAuto.php",
    "textdomain": "site--templates--webkitlagerauto-php",
    "translations": {
        "99fa307ec57145b928f70f1bf9a6b0f9": {
            "text": "de"
        },
        "399a817877af458537114697dbdcd1ec": {
            "text": "Trier par :"
        },
        "f85a094911f1791512a9c6c340af8501": {
            "text": "Les v\u00e9hicules sont charg\u00e9s :"
        },
        "ceab854bab8563c4c37d5411abf61119": {
            "text": "Rechercher un v\u00e9hicule"
        },
        "17a1115519a7d611cea6663f039fc617": {
            "text": "Tous les types de v\u00e9hicules"
        },
        "05db64b63f46a0d66ebaf9b6c52640da": {
            "text": "Tous les types de v\u00e9hicules"
        },
        "ca4c95edfc1cb0bb7834c03181db5db3": {
            "text": "Toutes les marques"
        },
        "d14ce9b3f96539a2b0cddce3f3d10964": {
            "text": "Tous les mod\u00e8les"
        },
        "7ba626b3662c671ae1649986cb0d2946": {
            "text": "Tous les types de carrosserie"
        },
        "cd9454ac308cd2e6664aa6a05bf8ebe6": {
            "text": "Tous les carburants"
        },
        "2f43b4b9f99a34adbbc4c2dce12bdbf0": {
            "text": "Toutes les ann\u00e9es"
        },
        "3551dcebb592af19007be6dccbe904cb": {
            "text": "Tous les entra\u00eenements"
        },
        "02355d02162809861896c8c313d038cb": {
            "text": "Tous les engrenages"
        },
        "4474fbc0115b236a45eb9573889b2653": {
            "text": "Rechercher"
        }
    }
}

Noteworthy:

  • We use markup regions and this installation is ProcessWire 3.0.229.
    • $config->useMarkupRegions = true;
    • $config->appendTemplateFile = '_main.php';
  • In a different template, where the subtemplate is loaded with required_once(), this works:

I am thoroughly confused.

Link to comment
Share on other sites

Thanks. In the _main.php template that should not be a possibility. But considering nothing else is working, I added the namespace to the template. No change.

I also upgraded PW to 3.0.235. But still no luck.

Any other ideas how to resolve this.

Link to comment
Share on other sites

On 2/1/2024 at 10:40 PM, da² said:

Hello,

maybe a missing "namespace Processwire;" ?

OK. After upgrading to the latest version of PW I managed to make it work by adding the namespace to each tempalte. But this still seems strange, as we have an identical installation which works fine without having to add the pw namespace manually to tempaltes.

  • Like 1
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...