insert translation even in script part

Posted 1 year ago by jahstation

I'm using the translation, in blade template.

My blade page have in the footer part things like:

@push('scripts')
<link href={{asset('/css/bootstrap2-toggle.min.css')}} rel="stylesheet">
<script src={{asset('/js/bootstrap2-toggle.min.js')}}></script>
<script src="{{asset("js/jquery.smartWizard.js")}}"></script>
<script src={{asset('/js/stepper.js')}}></script>
<script src={{asset('/js/validationJquery.js')}}></script>
@endpush

I need to force some parts of my JS file, with translation. If I write inside the file (public/js/steppers.js for example) things like: var cancelVal={{ __('messages.tempCreat_txtLock') }}; This not works;

If I write:

<script>
        var cancelVal={{ __('messages.tempCreat_txtLock') }};
    </script>

or

<script>
        var cancelVal={!! __('messages.tempCreat_txtLock') !!};
    </script>

or

<script>
        var cancelVal=' '+{{ __("messages.tempCreat_txtLock") }}+' ';
    </script>

or

<script>
        var cancelVal=' '+{!! __("messages.tempCreat_txtLock") !!}+' ';
    </script>

Before or inside the PUSH(script) part, this works and in the doom I can see the correct value, but highlited in red, in the dom I can see thing like:

<script>
        var cancelVal=lock;   <-- Lock is not defined
    </script>

Or

<script>
        var cancelVal=''+Lock+'';   <-- Lock is not defined
    </script>

And in the file public/js/stepper.js the variable "cancelVal" is not defined.

How can I make it works?

thanks a lot

Please sign in or create an account to participate in this conversation.