fransjaeger Posted January 17, 2015 Share Posted January 17, 2015 (edited) example i have $this->l('Discount for your cancelled cart') How could i make sure its translated to $id_langI 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 January 17, 2015 by michaelhjulskov (see edit history) Link to comment Share on other sites More sharing options...
El Patron Posted January 18, 2015 Share Posted January 18, 2015 hi, is this logic executed while the customer is active or is this done from back office and you want to send the correct translation based on customer language? Link to comment Share on other sites More sharing options...
fransjaeger Posted January 18, 2015 Author Share Posted January 18, 2015 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 More sharing options...
fransjaeger Posted January 18, 2015 Author Share Posted January 18, 2015 (edited) Anyhow maybe this is an issue, maybe its not an issue. Not really so relevant for me as i only have one language an i will never see the issue. BUT I am writing another module where I want to do it correcttly. So thats another reason that I need to know how i do this? Edited January 19, 2015 by michaelhjulskov (see edit history) Link to comment Share on other sites More sharing options...
El Patron Posted January 18, 2015 Share Posted January 18, 2015 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 More sharing options...
fransjaeger Posted January 18, 2015 Author Share Posted January 18, 2015 (edited) 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_langI 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 January 18, 2015 by michaelhjulskov (see edit history) Link to comment Share on other sites More sharing options...
fransjaeger Posted January 18, 2015 Author Share Posted January 18, 2015 To show exactly where in followup I see this problem: https://github.com/PrestaShop/followup/blob/master/followup.php#L164 Link to comment Share on other sites More sharing options...
fransjaeger Posted January 18, 2015 Author Share Posted January 18, 2015 (edited) 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 January 18, 2015 by michaelhjulskov (see edit history) Link to comment Share on other sites More sharing options...
fransjaeger Posted January 18, 2015 Author Share Posted January 18, 2015 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 More sharing options...
fransjaeger Posted January 21, 2015 Author Share Posted January 21, 2015 Any one Please help, I need this fixed asap. Link to comment Share on other sites More sharing options...
fransjaeger Posted January 24, 2015 Author Share Posted January 24, 2015 Look this should be a very simple question to answer? How to I set locale language to $id_lang before $this->l('Discount for your cancelled cart') There must be some developer who can teach me this Come ON !!!! Link to comment Share on other sites More sharing options...
Prestashop Addict Posted December 27, 2023 Share Posted December 27, 2023 Very old question, but this code could help someone in same use case. $language = new Language($customer->id_lang); $locale = $language->getLocale(); Mail::send( $customer->id_lang, 'your_emplate_mail', $this->l('Account enable', false, $locale), ... ); Be sure to have the locale/iso translation available. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now