0

I'm working on a Laravel 5.4 project and I need to include specific js script (or any other resource type like image and css) based on user selected language. Currently I use follow syntax:

{!! HTML::script('js/jquery-validation/jquery.validate.min.js') !!}

than correctly include the main js file that is valid for all languages.

The validate plugin show error messages based on user browser language but I want that the language change when the user choose a different language.

So i try:

{!! HTML::script('js/jquery-validation/localization/messages_'){{ Config::get('app.locale') }} !!}

and

{!! HTML::script('js/jquery-validation/localization/messages_') !!}{{ Config::get('app.locale') }}

But both don't work.

The first one throw an exception, the second one produce wrong code

<script src="http://dev-site.me/js/jquery-validation/localization/messages_"></script>
de.js

(obliviously.. because the "locale" part is outside the include declaration.. but I just try.. :P )

so I need a way to create an html like:

<script src="http://yearly-review.me/js/jquery-validation/localization/messages_de.js"></script>

where de.js is a dynamic part based on a variable how can I do this?

1
  • Try @php $url = 'js/jquery-validation/localization/messages_'.Config::get('app.locale')@endphp {{{!! HTML::script($url)!!}} Commented Dec 26, 2018 at 23:59

1 Answer 1

1

try it once:

{!! Html::script('js/jquery-validation/localization/messages_' . config('app.locale')) !!}
Sign up to request clarification or add additional context in comments.

2 Comments

Perfect!! thank you! a so simple solution :P just to be more correct.. the final right solution is {!! Html::script('js/jquery-validation/localization/messages_' . config('app.locale').".js") !!} otherwise you miss the extension
I am so sorry. It is my mistake.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.