Jump to content

[SOLVED] Currency symbol translation


Recommended Posts

Topic moved

I suggest modifying classes/Tools.php and adding the following in the displayPrice function after the $c_char = line:

if ($c_char == 'kr' AND $cookie->id_lang == 8)
   $c_char = 'кр';



Change 8 to the id of the Russian language on your website.

You may need to add the following at the start of the function to allow access to the cookie:

global $cookie;

Link to comment
Share on other sites

Thank you for the prompt reply.

when I inserted the cookie, I received an error 'cannot link to the database'. Where exactly should I insert the cookie?

Also it says 'if you modified this function, don't forget to modify the Javascript function formatCurrency (in tools.js) if ($convert)*/, what sould I modify in there?


static public function displayPrice($price, $currency, $no_utf8 = false, $convert = true)
   {
       /* if you modified this function, don't forget to modify the Javascript function formatCurrency (in tools.js) */
       if ($convert)
           $price = self::convertPrice($price, $currency);
       if (is_int($currency))
           $currency = new Currency(intval($currency));
       $c_char = (is_array($currency) ? $currency['sign'] : $currency->sign);
       if ($c_char == 'kr' AND $cookie->id_lang == 4)
       $c_char = 'кр'; 
       $c_format = (is_array($currency) ? $currency['format'] : $currency->format);
       $c_decimals = (is_array($currency) ? intval($currency['decimals']) : intval($currency->decimals)) * _PS_PRICE_DISPLAY_PRECISION_;
       $c_blank = (is_array($currency) ? $currency['blank'] : $currency->blank);
       $blank = ($c_blank ? ' ' : '');
       $ret = 0;
       if (($isNegative = ($price < 0)))
           $price *= -1;
       switch ($c_format)
        {
             /* X 0,000.00 */
             case 1:
               $ret = $c_char.$blank.number_format($price, $c_decimals, '.', ',');
               break;
           /* 0 000,00 X*/
           case 2:
               $ret = number_format($price, $c_decimals, ',', ' ').$blank.$c_char;
               break;
           /* X 0.000,00 */
           case 3:
               $ret = $c_char.$blank.number_format($price, $c_decimals, ',', '.');
               break;
           /* 0,000.00 X */
           case 4:
               $ret = number_format($price, $c_decimals, '.', ',').$blank.$c_char;
               break;
       }
       if ($isNegative)
           $ret = '-'.$ret;
       if ($no_utf8)
           return str_replace('€', chr(128), $ret);
       return $ret;
   }

Link to comment
Share on other sites

It should be the first line of the function like this:

static public function displayPrice($price, $currency, $no_utf8 = false, $convert = true)
   {
       /* if you modified this function, don't forget to modify the Javascript function formatCurrency (in tools.js) */
       global $cookie;
       if ($convert)
           $price = self::convertPrice($price, $currency);
       if (is_int($currency))
           $currency = new Currency(intval($currency));
       $c_char = (is_array($currency) ? $currency['sign'] : $currency->sign);
       if ($c_char == 'kr' AND $cookie->id_lang == 4)
       $c_char = 'кр'; 
       $c_format = (is_array($currency) ? $currency['format'] : $currency->format);
       $c_decimals = (is_array($currency) ? intval($currency['decimals']) : intval($currency->decimals)) * _PS_PRICE_DISPLAY_PRECISION_;
       $c_blank = (is_array($currency) ? $currency['blank'] : $currency->blank);
       $blank = ($c_blank ? ' ' : '');
       $ret = 0;
       if (($isNegative = ($price < 0)))
           $price *= -1;
       switch ($c_format)
        {
             /* X 0,000.00 */
             case 1:
               $ret = $c_char.$blank.number_format($price, $c_decimals, '.', ',');
               break;
           /* 0 000,00 X*/
           case 2:
               $ret = number_format($price, $c_decimals, ',', ' ').$blank.$c_char;
               break;
           /* X 0.000,00 */
           case 3:
               $ret = $c_char.$blank.number_format($price, $c_decimals, ',', '.');
               break;
           /* 0,000.00 X */
           case 4:
               $ret = number_format($price, $c_decimals, '.', ',').$blank.$c_char;
               break;
       }
       if ($isNegative)
           $ret = '-'.$ret;
       if ($no_utf8)
           return str_replace('€', chr(128), $ret);
       return $ret;
   }

Link to comment
Share on other sites

  • 5 months 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...