Jump to content

language translation in templates stopped working


Soma
 Share

Recommended Posts

Somehow on a page I use PW translations: echo __("Text string") it stopped working showing the alternative language. Before it was all ok. I updated the core to latest 2.2.9. No luck.

Before I updated to 2.2.6 and there it seems it stopped working. I didn't recognize until now.

The page is a formular: http://www.velokurie...ine-bestellung/ and you can cahnge to english using the link above the form. So only the formular is/should be translated (not the rest of the page).

I didn't change anything so I'm a little lost as to why and how.

Language is set like this:

if($input->get->lang){
 $lang = $sanitizer->pageName($input->get->lang);
 $langfield = "_en";
} else {
 $lang = 'default';
 $langfield = '';
}

$user->language = $languages->get($lang);

Then in the formular the texts are outputed like this:

<?php echo __("Vorname / Name")?>

And it worked really well, until now.

Any ideas?

Link to comment
Share on other sites

Ok, I tested on my local test install 2.2.9 and it works normally with translations in templates.

But can't get it to work on that host. Only difference I know is php version.

Locally PHP 5.2.9 and on the server where it doesn't work PHP 5.2.4.

So, strange thing it works when I put in PW 2.2.2.

Link to comment
Share on other sites

I have no idea why it suddenly stoped working but found out if I add the language domain the text translation works. Like __("text",__FILE__);

__("text"); simply stopped working for some reason I don't know.

It would be great to not have to add __FILE__ to each text phrase.

Link to comment
Share on other sites

Soma I don't have a 5.2.4 to test on, but if you try modifying that debug_backtrace does it also fix the issue?

The issue with 2.2.9 showing the value rather than the label for a checkbox is unrelated -- I think I know what's causing it, it's related to some new features I recently added to the checkbox inputfield. Should be an easy fix.

Link to comment
Share on other sites

I can't get it to work with modifying the debug_backtrace.

Why does it not find the text domain and works in PW 2.2.2?

Is that related to some other part? No matter what I do, it must be that __() function not finding the template file?

Link to comment
Share on other sites

No idea why it would make any difference between 2.2.2 and now. There haven't been any changes to the stuff in question. For instance, the last change made to LanguageFunctions.php (where the __ function lives) was related to our previous thread, 4 months ago:

https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/LanguageFunctions.php

The only thing I can figure at this point is PHP 5.2.4, which is known to have bugs. If you want to try and troubleshoot it a little more, try taking a look at what exactly the __() function is sending to the translator. So add this line:

if($text == "whatever your text is") echo "<p>Textdomain: $textdomain</p>";

right before this:

return htmlspecialchars($language->translator()->getTranslation($textdomain, $text, $context), ENT_QUOTES, 'UTF-8');
Link to comment
Share on other sites

The only way I can get it to work would be:

if(is_null($textdomain)) {
 if(defined('DEBUG_BACKTRACE_IGNORE_ARGS'))
   $traces = @debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
     else $traces = @debug_backtrace();
  • 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...