Jump to content

[SOLVED] Translate Currency Symbol/Name


sickshot

Recommended Posts

Hi sickshot,

No solution yet, but maybe an idea that gets you started. I have a javascript that checks the body for instances of the currency (I believe you use GEL and ლარი, right?

 

If you add the following code to themes/<your theme folder>/header.tpl (just above the line

        {$HOOK_HEADER}

 INside the  <head>...</head> tag ))

 

 

{assign var="hdr_language" value=Context::getContext()->language->id}
<script>
  $(document).ready(function() {
    if ({$hdr_language} == XXXX) {
      var replaced=document.body.innerHTML.replace(/GEL/g,'ლარი');
      document.body.innerHTML=replaced;


    }
  });
</script>

 

(and Replace XXXX witht the language ID of your Georgian language in PrestaShop)

In Localization->Currencies, use GEL as Unit of Currency.

 

What it does is, when the Language changes to Georgian, it will replace the GEL with ლარი.

 

This sounds great, but I bumped into a few problems:

- After replacing the body text with the new 'replaced' (in the line: document.body.innerHTML=replaced;), not all javascripts seem to work anymore, like the shoppingcart won't fold open, the top menu- drop down menu's won't open etc.

- When adding some product to the cart, I expect that the added product still has the GEL as currency unit, as it won't be 'translated' on the fly, only one time, when loading the page the first time.

 

 

So, this won't fully work, but it may give you some idea how wo do the translation. Maybe someone else has a great idea where to put this code to make it work everywhere and correctly with the diverse scripts...

 

My 2 cents,

pascal.

  • Like 1
Link to comment
Share on other sites

hello and thank you for your replays!

 

Pascal  you're right thats exactly my case :) I'll check and see whats happens then :) I'll get back with the results..

 

El Patron

 

 

No. sound silly but we dont have a symbol :D we use only GEL when needed in English as USD is used... 

  • Like 1
Link to comment
Share on other sites

Hi Sickshot,

 

I think I found an easy way!

 

Edit file: classes/tools.php

find the function:

    public static function displayPrice($price, $currency = null, $no_utf8 = false, Context $context = null)
 

	public static function displayPrice($price, $currency = null, $no_utf8 = false, Context $context = null)
	{
		if (!is_numeric($price))
			return $price;
		if (!$context)
			$context = Context::getContext();
		if ($currency === null)
			$currency = $context->currency;
		// if you modified this function, don't forget to modify the Javascript function formatCurrency (in tools.js)
		elseif (is_int($currency))
			$currency = Currency::getCurrencyInstance((int)$currency);

		if (is_array($currency))
		{
			$c_char = $currency['sign'];
			$c_format = $currency['format'];
			$c_decimals = (int)$currency['decimals'] * _PS_PRICE_DISPLAY_PRECISION_;
			$c_blank = $currency['blank'];
		}
		elseif (is_object($currency))
		{
			$c_char = $currency->sign;


			$c_format = $currency->format;
			$c_decimals = (int)$currency->decimals * _PS_PRICE_DISPLAY_PRECISION_;
			$c_blank = $currency->blank;
		}
		else
			return false;

		$blank = ($c_blank ? ' ' : '');
		$ret = 0;
		if (($is_negative = ($price < 0)))
			$price *= -1;
		$price = Tools::ps_round($price, $c_decimals);
		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;
			/* 0 000.00 X  Added for the switzerland currency */
			case 5:
				$ret = number_format($price, $c_decimals, '.', ' ').$blank.$c_char;
				break;
		}
		if ($is_negative)
			$ret = '-'.$ret;
		if ($no_utf8)
			return str_replace('€', chr(128), $ret);
		return $ret;
	}

	

and add the follwing lines:

                if ((int)Context::getContext()->language->id == XXXX)  // XXXX is langage ID of Greorgian

                      $c_char ='ლარი';                                 // (see your Localization->Languages)

   like this:

	public static function displayPrice($price, $currency = null, $no_utf8 = false, Context $context = null)
	{
		if (!is_numeric($price))
			return $price;
		if (!$context)
			$context = Context::getContext();
		if ($currency === null)
			$currency = $context->currency;
		// if you modified this function, don't forget to modify the Javascript function formatCurrency (in tools.js)
		elseif (is_int($currency))
			$currency = Currency::getCurrencyInstance((int)$currency);

		if (is_array($currency))
		{
			$c_char = $currency['sign'];
			$c_format = $currency['format'];
			$c_decimals = (int)$currency['decimals'] * _PS_PRICE_DISPLAY_PRECISION_;
			$c_blank = $currency['blank'];
		}
		elseif (is_object($currency))
		{
			$c_char = $currency->sign;


			$c_format = $currency->format;
			$c_decimals = (int)$currency->decimals * _PS_PRICE_DISPLAY_PRECISION_;
			$c_blank = $currency->blank;
		}
		else
			return false;


                if ((int)Context::getContext()->language->id == XXXX)  // <-- add here
                        $c_char ='ლარი';

		$blank = ($c_blank ? ' ' : '');
		$ret = 0;
		if (($is_negative = ($price < 0)))
			$price *= -1;
		$price = Tools::ps_round($price, $c_decimals);
		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;
			/* 0 000.00 X  Added for the switzerland currency */
			case 5:
				$ret = number_format($price, $c_decimals, '.', ' ').$blank.$c_char;
				break;
		}
		if ($is_negative)
			$ret = '-'.$ret;
		if ($no_utf8)
			return str_replace('€', chr(128), $ret);
		return $ret;
	}

	

resullt:

before changing to Greorgian language:

post-455771-0-18829500-1396295155_thumb.png

 

after:

post-455771-0-31316300-1396294753_thumb.png

 

If you have more languages that you support, you can change the line to something like:

 

if (((int)Context::getContext()->language->id == XXXX) AND ((int)Context::getContext()->currency->id == YYYY)) //
$c_char ='ლარი';
 

Where YYYY is currency ID of Greorgian currency

 

 

Hope that helps,

pascal.

Link to comment
Share on other sites

Hi sickshot,

 

Don't add the name of the language, but it's ID number:

post-455771-0-56332600-1396298959_thumb.png

 

So for example, if your language ka has an ID of 2:

 

Don't add:

if ((int)Context::getContext()->language->id == ka)
                         $c_char ='ლარი';

 

 

but

if ((int)Context::getContext()->language->id == 2)
                         $c_char ='ლარი';

 

That should do the trick.

 

pascal

Link to comment
Share on other sites

Sorry.... :wacko:    Didn't work with 1.4 for a while...

 

add:

global $cookie;

 

 

global $cookie;

if ((int)$cookie->id_lang == 2)
       $c_char ='ლარი';

 

total function:

	public static function displayPrice($price, $currency = NULL, $no_utf8 = false)
	{
		if ($currency === NULL)
			$currency = Currency::getCurrent();
		/* if you modified this function, don't forget to modify the Javascript function formatCurrency (in tools.js) */
		if (is_int($currency))
			$currency = Currency::getCurrencyInstance((int)$currency);
		
		if (is_array($currency))
		{
			$c_char = $currency['sign'];
			$c_format = $currency['format'];
			$c_decimals = (int)$currency['decimals'] * _PS_PRICE_DISPLAY_PRECISION_;
			$c_blank = $currency['blank'];
		}
		elseif (is_object($currency))
		{
			$c_char = $currency->sign;
			$c_format = $currency->format;
			$c_decimals = (int)$currency->decimals * _PS_PRICE_DISPLAY_PRECISION_;
			$c_blank = $currency->blank;
		}
		else
			return false;



		global $cookie;
 		if ((int)$cookie->id_lang == 1)  // replace 1 with language ID where GEL should be replaced with ლარი
                         $c_char ='ლარი';


		
		$blank = ($c_blank ? ' ' : '');
		$ret = 0;
		if (($isNegative = ($price < 0)))
			$price *= -1;
		$price = self::ps_round($price, $c_decimals);
		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;
	}

Hope this really does the trick.

 

Can you give me the URL to see the result?

 

pascal

Link to comment
Share on other sites

Please edit themes/<your theme folder>/js/tools.js  (make backup, just in case)

 

edit Function formatCurrency:

 

//return a formatted price
function formatCurrency(price, currencyFormat, currencySign, currencyBlank)
{
    // if you modified this function, don't forget to modify the PHP function displayPrice (in the Tools.php class)
    blank = '';
    price = Number(price);
    price = parseFloat(price.toFixed(6));
    price = ps_round(price, priceDisplayPrecision);

    global $cookie;
    if ((int)$cookie->id_lang == 1)
        $currencySign ='ლარი';


    if (currencyBlank > 0)
        blank = ' ';

...

 

I think we're finally there....

pascal

  • Like 1
Link to comment
Share on other sites

  • 2 years later...
  • 5 months later...

Please edit themes/<your theme folder>/js/tools.js  (make backup, just in case)

 

edit Function formatCurrency:

 

//return a formatted price

function formatCurrency(price, currencyFormat, currencySign, currencyBlank)

{

    // if you modified this function, don't forget to modify the PHP function displayPrice (in the Tools.php class)

    blank = '';

    price = Number(price);

    price = parseFloat(price.toFixed(6));

    price = ps_round(price, priceDisplayPrecision);

 

    global $cookie;

    if ((int)$cookie->id_lang == 1)

        $currencySign ='ლარი';

 

    if (currencyBlank > 0)

        blank = ' ';

...

 

I think we're finally there....

pascal

Hello Pascal,
 
Can you please tell us how can i translate Currency Sign from "RON" to "LEI" in Prestashop 1.7?
 
 
Thank you!
Edited by rl_lucian (see edit history)
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...