Jump to content

Hanna code translations error


Krlos
 Share

Recommended Posts

Hi, I'm trying to use hanna code with translations but it gives me an error:

Oh no… Fatal Error: 	Uncaught Error: Call to undefined function __() in site/assets/cache/HannaCode/guia_turistico_hanna.php

I'm using:

<?php echo __("Ver detalles"); ?>

for translations output.

Thanks in advance.

Link to comment
Share on other sites

3 minutes ago, Ivan Gretsky said:

Did you define a ProcessWire namespace?

Hi Ivan,

yes, I have this on my Hanna code PHP

<?php namespace ProcessWire; ?>

<?php $alojamiento = $pages->find("template=alojamiento, limit=10");
  foreach ($alojamiento as $a):
?>

... More HTML and PHP code

<a><?php echo __("Ver detalle"); ?></a>

the last part with the a tag is throwing the error.

Link to comment
Share on other sites

13 hours ago, MarkE said:

The hack in the quoted post is quite simple @Krlos - you may wish to try it and see if it fixes your problem. If not, you can revert. 
Or you could just try \ProcessWire\_(“….”)

Hi @MarkE,

Thankyou for your help, I will try your suggestion.

Where should I put that code you posted?, before every hanna code block?

This:

$php = '<' . '?php';
		$openPHP = $php;
		$openPHPNS = "$php namespace ProcessWire;";
		$firstLine = 'if(!defined("PROCESSWIRE")) die("no direct access");';
		
		if(strpos($code, 'namespace') && preg_match('/(namespace\s+ProcessWire(?:;|\s*;))/', $code, $matches)) {
			$openPHP = $openPHPNS;
			$code = str_replace($matches[1], '', $code);
		}

		if(strpos($code, $openPHP) !== 0 && strpos($code, $php) !== 0) {
			// prepend open PHP tag to code if not already present
			$code = "$openPHPNS\n$firstLine\n$code"; 
		} else {
			// otherwise insert our $firstLine security check
			$code = str_replace($php, "$openPHPNS\n$firstLine\n", $code);
		}

I don't understand this code:

\ProcessWire\_(“….”) 

Should I replace that for this?

<?php namespace ProcessWire; ?>

Thankyou

Link to comment
Share on other sites

I suggest you try the simple thing first:

Replace 

<a><?php echo __("Ver detalle"); ?></a>

by

<a><?php echo \ProcessWire\__("Ver detalle"); ?></a>

Let me know if that works - then I know we have the same namesapce issue as I have already reported

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