Jump to content

Get string translation per language


Tuni-Soft

Recommended Posts

Hello

 

For translation i use

$this->l($str)

but this returns the translated string for the current language.

 

I'm looking for a way to get the translated string per language i.e. get the translation of a given string in all available languages.

 

I inspected the class in translate.php but came out with no solution!

any help is much appreciated

Thank you

Link to comment
Share on other sites

Thank you, i finally figured it out

 

this function can be included in your module

 


/**
* Return the translation for a string given a language iso code 'en' 'fr' ..
*
* @public
* @param $string string to translate
* @param $iso_lang language iso code
* @param $source source file without extension
* @param $js if it's inside a js string
* @return string translation
*/
public function _translate($string,$iso_lang,$source,$js=false){
  $file = dirname(__FILE__).'/translations/'.$iso_lang.'.php';
  if(!file_exists($file)) return $string;
  include($file);
  $key = md5(str_replace('\'', '\\\'', $string));
  $current_key = strtolower('<{'.$this->name.'}'._THEME_NAME_.'>'.$source).'_'.$key;
  $default_key = strtolower('<{'.$this->name.'}prestashop>'.$source).'_'.$key;
  $ret = $string;
  if (isset($_MODULE[$current_key]))
   $ret = stripslashes($_MODULE[$current_key]);
  elseif (isset($_MODULE[$default_key]))
   $ret = stripslashes($_MODULE[$default_key]);
  if ($js)
   $ret = addslashes($ret);
  return $ret;
 }

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