Jump to content

Howto translate a string to $id_lang


fransjaeger

Recommended Posts

example i have $this->l('Discount for your cancelled cart')

How could i make sure its translated to $id_lang
I have seen this

Mail::l('Discount for your cancelled cart', $id_lang)

but would it work everywhere, or is there another more clean method I should use?

 

Im thinking maybe its possible to do something like:

$old_id_lang=get_curret_id_lang();
set_id_lang($id_lang);
$a=$this->l('Discount for your cancelled cart');
set_id_lang($old_id_lang);
echo $a;

By the way i need this because i found out that module "followup" doesnt translate correctly a in some lines.

 

Thanks

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

Hi, It is triggered by a cronjob call that triggers the function. Function is looping through customers from all countries in a big mess, so thats why I think its an issue that lang is not taken in as param. In this case its used to produce a voucher for the customer, but the voucher name will be in same language for all customers. I dont know if customer ever see that voucher name, but I guess so.

Link to comment
Share on other sites

maybe this will help.

here is an example of sending email by customer language: 

$this->cust_lang = self::_getCustomerLang();
	Mail::Send(
	(int)$this->cust_lang,
	$template,Mail::l('Some Subject also xlated to other langs'),


	//before 1.5.4 the customer language is not stored by prestashop.
	private function _getCustomerLang()
	{
		if (substr(_PS_VERSION_, 0, 7) >= '1.5.4.1') 		 {
			$sql = 'SELECT `id_lang`
			FROM `'._DB_PREFIX_.'customer`
			WHERE 1 '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).'AND `id_customer` = '.$this->context->customer->id.'';
			$result = Db::getInstance()->getRow($sql);
			return $result['id_lang'];
		}else{
			return $result = (int)(Configuration::get('PS_LANG_DEFAULT'));
		}
	}


Link to comment
Share on other sites

Hi

Thanks but this is not the same scenario, sorry

this isnt a mail. its a function that return a string in a given language

and I already know customers id_lang

I think what im looking for is maybe Mail::l('Discount for your cancelled cart', $id_lang)

or something simular..

 

I can show you again what I mean. If you imagine this is inside a function

 

example 1

foreach($customers as $id_customer => $id_lang)
  $old_id_lang=get_current_id_lang();
  set_id_lang($id_lang);
  $a[$id_customer] = $this->l('Discount for your cancelled cart');
  set_id_lang($old_id_lang);
}
return $a;

example 2 (i like this best but i dont think it will work)

foreach($customers as $id_customer => $id_lang)
  $a[$id_customer] = Mail::l('Discount for your cancelled cart', $id_lang); 
}
return $a;
Edited by michaelhjulskov (see edit history)
Link to comment
Share on other sites

In fact I think what is needed is to setlocale() before and after translating the string.

something like (i know this isnt correct, but as example to show what i need)

$old_locale=get_locale();
foreach($customers as $id_customer => $id_lang)
  if ($old_locale != $id_lang)setlocale($id_lang);
  $a[$id_customer] = $this->l('Discount for your cancelled cart');
  if ($old_locale != $id_lang)setlocale($old_locale);
}
return $a;

A little like what happens in /config/config.inc.php see here

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

I have located this function in a module i bought

Maybe this can be used for inspiration?

 protected function localize($langCode) {
        require "lang/{$langCode}.php";
        setlocale(LC_ALL, $lang['_locale']);
        $this->charset = $lang['_charset'];
        $this->dateTimeFull = $lang['_dateTimeFull'];
        $this->dateTimeMid = $lang['_dateTimeMid'];
        $this->dateTimeSmall = $lang['_dateTimeSmall'];
        unset($lang['_locale']);
        unset($lang['_charset']);
        unset($lang['_dateTimeFull']);
        unset($lang['_dateTimeMid']);
        unset($lang['_dateTimeSmall']);
        $this->labels = $lang;
    }
Link to comment
Share on other sites

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