Can I use dynamic JS variable in html?

I have some dynamic JS variable in html page for localization purpose, But I separate all JS functional script as external link. Can I use JS variable like this way :

   * Make JS variable
  "use strict";
  var locale = "{{ app()->getLocale() }}";
  var success = "{{ __('Success') }}";
  var error = "{{ __('Error') }}";
  var statusMsg = "{{ __('Status updated sucesssfully.') }}";
  var successMsg = "{{ __('Organization created successfully.') }}";
<!-- select2 -->
<script src="/assets/script/select2-bootstrap.js"></script>
<!-- datatables -->
<script src="/assets/datatables/js/jquery.dataTables.min.js"></script>
<script src="/assets/datatables/js/dataTables.bootstrap4.min.js"></script>
<!-- page script-->
<script src="/assets/script/organization/index.js"></script>

Hi @TeehaLab, I can’t see your script is dynamic. If dynamic then those text should come from a language file and from backend settings (settings form).

1 Like

Thank you. I edited my question. would you please check :slight_smile:

if you handle those variable dynamically then allowed.


Yes, this variable is coming from app language files, if the user switch their language then the variable will change.

1 Like