Jump to content

Translation inside a js


Recommended Posts

Bonjour,

 

I have in my back/front office added the concept of attributes availability. In order to display the attributes product availability in Frensh or englih or GR ...

 

I use the JS solution to display the reference attribute and it work good but I can't find a solution to translate "available", "on order", "out of stock", "resupply", "pre order"

 

How this works:

Depending on the value of dispo_code I set the availability to "available", "on order",... and I show the availability with jquery.

 

Here is my js inside product.js of my template to set the availability:

 

//add a combination of attributes in the global JS sytem
function addCombination(idCombination, arrayOfIdAttributes, quantity, price, ecotax, id_image, reference, unit_price, minimal_quantity, dispo_date, dispo_code)
{
globalQuantity += quantity;
var combination = new Array();
combination['idCombination'] = idCombination;
combination['quantity'] = quantity;
combination['idsAttributes'] = arrayOfIdAttributes;
combination['price'] = price;
combination['ecotax'] = ecotax;
combination['image'] = id_image;
combination['reference'] = reference;
combination['unit_price'] = unit_price;
combination['minimal_quantity'] = minimal_quantity;
 if(quantity>0){dispo_code=1}
  if(dispo_code==1){combination['dispo_code'] = 'Available'}
  if(dispo_code==2){combination['dispo_code'] = 'on order'}
  if(dispo_code==3){combination['dispo_code'] = 'out of stock'}
  if(dispo_code==4){combination['dispo_code'] = 'resupply'}
  if(dispo_code==5){combination['dispo_code'] = 'pre order'}
  if(dispo_code==1){combination['dispo_date'] = ''}
 else {combination['dispo_date'] = dispo_date;}
combinations.push(combination);
}

 

And here is my JS code inside product.js of my template to show the availability:

if (selectedCombination['dispo_date'])
{
  $('#product_dispo_date span').text(selectedCombination['dispo_date']);
  $('#product_dispo_date:hidden').show('slow');
}
else
 $('#product_dispo_date:visible').hide('slow');

if (selectedCombination['dispo_code'])
{
  $('#product_dispo_code span').text(selectedCombination['dispo_code']);
  $('#product_dispo_code:hidden').show('slow');
}
else
 $('#product_dispo_code:visible').hide('slow');
 $('#product_dispo_coda:visible').hide('slow');

 

 

Many thanks !!

 

Ckarone

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

I have the solution :rolleyes:

 

Just set in product.tlp some variables for each status with translation in lan/fr.php or lan/en.php :

var myavailable = '{l s='Available' js=1}';
var myoutofstok = '{l s='Out of stock' js=1}';
var myononoreder = '{l s='On order' js=1}';
var myresupply = '{l s='Resupply' js=1}';
var mypreorder = '{l s='Pre order' js=1}';

 

and depending on the dispo_code value show the good status

if (selectedCombination['dispo_code'])
{
 if (selectedCombination['dispo_code'] ==1)
  $('#product_dispo_code span').text(myavailable);
 if (selectedCombination['dispo_code'] ==2)
  $('#product_dispo_code span').text(myresupply);
 if (selectedCombination['dispo_code'] ==3)
  $('#product_dispo_code span').text(myoutofstock);
 if (selectedCombination['dispo_code'] ==4)
  $('#product_dispo_code span').text(myonorder);
 if (selectedCombination['dispo_code'] ==5)
  $('#product_dispo_code span').text(mypreorder);

  $('#product_dispo_code:hidden').show('slow');
}
else
 $('#product_dispo_code:visible').hide('slow');
 $('#product_dispo_coda:visible').hide('slow');

 

Wasn't some complicated ;)

 

Sorry for my bad english

 

Ckarone

Edited by ckarone (see edit history)
  • Like 2
Link to comment
Share on other sites

  • 1 year later...
  • 1 month later...

I have the solution :rolleyes:

 

Just set in product.tlp some variables for each status with translation in lan/fr.php or lan/en.php :

var myavailable = '{l s='Available' js=1}';
var myoutofstok = '{l s='Out of stock' js=1}';
var myononoreder = '{l s='On order' js=1}';
var myresupply = '{l s='Resupply' js=1}';
var mypreorder = '{l s='Pre order' js=1}';
and depending on the dispo_code value show the good status

if (selectedCombination['dispo_code'])
{
  if (selectedCombination['dispo_code'] ==1)
   $('#product_dispo_code span').text(myavailable);
  if (selectedCombination['dispo_code'] ==2)
   $('#product_dispo_code span').text(myresupply);
  if (selectedCombination['dispo_code'] ==3)
   $('#product_dispo_code span').text(myoutofstock);
  if (selectedCombination['dispo_code'] ==4)
   $('#product_dispo_code span').text(myonorder);
  if (selectedCombination['dispo_code'] ==5)
   $('#product_dispo_code span').text(mypreorder);
  
   $('#product_dispo_code:hidden').show('slow');
}
else
  $('#product_dispo_code:visible').hide('slow');
  $('#product_dispo_coda:visible').hide('slow');
Wasn't some complicated ;)

 

Sorry for my bad english

 

Ckarone

 

I know this have little to do with your topic,

but i want to translate the availability state from product list (product-list.tpl) as in this topic here

I've tried to add the "js=1}" but isn't working...because I'm not a coder :huh: 

can you please help-me?

 

Tanks in Advance

Link to comment
Share on other sites

  • 1 year later...

Hi All,

 

I've tried this method for translating terms in my separate js file, unfortunately it didn't work.

 

Could somebody tell me it is possible to do the translation in separate js file or not, with PS1.6.0.14.

 

After reading this post

https://www.prestashop.com/forums/topic/263170-solved-translate-in-javascript/

 

Could I assume that the translation inside a js only works if you add <script> tags within template file?

 

Thanks in advance for your reply.

Link to comment
Share on other sites

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