mercredi 20 mars 2019

Laravel's localization on JavaScript Variables

I have some JavaScript variables that I output on a rating scale as shown below.

I now want to achieve Laravel's localization therefore translate the variables before outputting them on the browser.

How can I achieve this? I tried as below but it does not get converted.

var ratingScale = {1: 'Terrible, 2: 'Poor', 3: 'Average', 4: 'Good', 5: 'Excellent'}; 

I would want to Localize the variables Terrible, Poor, Average, Good, and Excellent.

I tried this

var one = "<?php echo trans('form.one'); ?>";

var ratingScale = {1: one, 2: 'Poor', 3: 'Average', 4: 'Good', 5: 'Excellent'};

But on the browser this is outputted <?php echo trans('form.one'); ?>

Anyone lead me here?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire