Jump to content

[solved]Translate module override Controller Admin


indesign47

Recommended Posts

Hello,

I have develop a module that override AdminImportController.php (1.5.4.1)

Module-> override-> controllers -> admin-> AdminImportController.php

Works fine execpt the translation of fields of AdminImportController.php

Fields of files tpl (View et Form) are working good.

Translation are save correctly in the file of translation fr.php but in the Form and in the View fields of AdminImportController.php are not translated into French !

File AdminImportController.php

$this->available_fields = array(
'link' => array('label' => $this->l('Link')),
);

File fr.php

global $_MODULE;
$_MODULE = array();
$_MODULE['<{importx}prestashop>adminimportcontroller_97e7c9a7d06eac006a28bf05467fcc8b'] = 'Lien';

I try to find a solution in AdminTranslationsController.php and translate.php but with no success.

 

Does anyone have a solution ? Thanks

 

Edit : SOLVED

Edited by indesign (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

Hi Valérie,

 

First, thanks for you answer

The translation is usually made in the backend and it doesn't matter if there was an override

Not sure understand what you mean exactly. (maybe because I am french ;) )

My module should bring all the translation (TPL, PHP) with the files > translation > fr.php or it.fr

It's right ?

 

I have a quiet look at your link, I should test it. Does it works with 1.5.4 ?

 

Best regards.

Link to comment
Share on other sites

Hi Valérie,

 

Find the solution ;)

 

Change nom_du_module with your name of module

Change AdminImportController with your name of controller

 

public static $l_cache;

protected function l($string, $class = 'AdminTab', $addslashes = FALSE, $htmlentities = TRUE)
{
	// need to be called in order to populate $classInModule
	$str = self::findTranslation('nom_du_module', $string, 'AdminImportController');
	$str = $htmlentities ? htmlentities($str, ENT_QUOTES, 'utf-8') : $str;
	return str_replace('"', '"', ($addslashes ? addslashes($str) : stripslashes($str)));
}

/**
 * findTranslation (initially in Module class), to make translations works
 *
 * @param string $name module name
 * @param string $string string to translate
 * @param string $source current class
 * @return string translated string
 */

public static function findTranslation($name, $string, $source)
{
	static $_MODULES;
	if (!is_array($_MODULES))
	{
		// note: $_COOKIE[iso_code] is set in createCustomToken();
		$file = _PS_MODULE_DIR_.'nom_du_module/translations/'.Context::getContext()->language->iso_code.'.php';
		if (file_exists($file) && include($file))
			$_MODULES = !empty($_MODULES)?array_merge($_MODULES, $_MODULE):$_MODULE;
	}
	$cache_key = $name.'|'.$string.'|'.$source;

	if (!isset(self::$l_cache[$cache_key]))
	{
		if (!is_array($_MODULES))
			return $string;
		// set array key to lowercase for 1.3 compatibility
		$_MODULES = array_change_key_case($_MODULES);
		if (defined('_THEME_NAME_'))
			$currentKey = '<{'.strtolower($name).'}'.strtolower(_THEME_NAME_).'>'.strtolower($source).'_'.md5($string);
		else
			$currentKey = '<{'.strtolower($name).'}default>'.strtolower($source).'_'.md5($string);
		// note : we should use a variable to define the default theme (instead of "prestashop")
		$defaultKey = '<{'.strtolower($name).'}prestashop>'.strtolower($source).'_'.md5($string);
		$currentKey = $defaultKey;

		if (isset($_MODULES[$currentKey]))
			$ret = stripslashes($_MODULES[$currentKey]);
		elseif (isset($_MODULES[strtolower($currentKey)]))
			$ret = stripslashes($_MODULES[strtolower($currentKey)]);
		elseif (isset($_MODULES[$defaultKey]))
			$ret = stripslashes($_MODULES[$defaultKey]);
		elseif (isset($_MODULES[strtolower($defaultKey)]))
			$ret = stripslashes($_MODULES[strtolower($defaultKey)]);
		else
			$ret = stripslashes($string);

		self::$l_cache[$cache_key] = $ret;
	}
	return self::$l_cache[$cache_key];
}

 

Thanks for your participation

Link to comment
Share on other sites

  • 4 years later...

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
×
×
  • Create New...