BazingaJsTranslationBundle icon indicating copy to clipboard operation
BazingaJsTranslationBundle copied to clipboard

Basic installation with script tags

Open tacman opened this issue 1 year ago • 8 comments

I'm missing something basic about how to load this.

            <script src="{{ asset('bundles/bazingajstranslation/js/translator.min.js') }}"></script>
            <script src="{{ url('bazinga_jstranslation_js') }}"></script>

translations:19 Uncaught ReferenceError: Translator is not defined at translations:19:4 (anonymous) @ translations:19

I've also been playing around with loading it as a module, but I figured I'd at least get a basic installation working first. Can anyone point me in the right direction?

Gracias.

tacman avatar May 10 '24 18:05 tacman

Hello @tacman, i'm in the same situation. Do you solve this error?

kasali avatar Aug 06 '24 11:08 kasali

No. I'll probably switch to https://symfony.com/bundles/ux-translator/current/index.html when I get around to focusing on javascript-based translations.

tacman avatar Aug 06 '24 11:08 tacman

is the translator.min.js file loaded properly or do you have another error before that for the loading of that file ?

stof avatar Aug 06 '24 13:08 stof

@stof , I see it's not loaded but it's present in the bundles/ directory. After following the doc here is my code :

{% block javascripts%}
  {{ parent() }}
    <script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap4.min.js"></script>
    
    <script src="{{ asset('bundles/bazingajstranslation/js/translator.min.js') }}"></script>
    <script src="{{ url('willdurand_js_translation_js', { 'domain': 'messages', 'locales': app.request.locale }) }}"></script>
    <script type="text/javascript" src="{{ asset('admin/js/sb-admin-2.min.js') }}"></script>
    <script src="{{ asset('/js/styles/datatable.js') }}"></script>
{% endblock %}

and here i want use the Translator object with Datatable:

var oTable = new DataTable(".dataTable", {
  paging: true,
  pageLength: 10,
  responsive: true,
  select: {
      style: "multi", // Enable multi-selection
      selector: "td:first-child", // Enable selection on the first column (checkbox)
  },
  language: {
      processing: Translator.trans('processing'),
      search: Translator.trans('search'),
      lengthMenu: Translator.trans('lengthMenu'),
      info: Translator.trans('info'),
      infoEmpty: Translator.trans('infoEmpty'),
      infoFiltered: Translator.trans('infoFiltered'),
      loadingRecords: Translator.trans('loadingRecords'),
      zeroRecords: Translator.trans('zeroRecords'),
      emptyTable: Translator.trans('emptyTable'),
      paginate: {
          first: Translator.trans('first'),
          previous: Translator.trans('previous'),
          next: Translator.trans('next'),
          last: Translator.trans('last'),
      },
      aria: {
          sortAscending: Translator.trans('aria.sortAscending'),
          sortDescending: Translator.trans('aria.sortDescending'),
      },
  },
});

kasali avatar Aug 07 '24 08:08 kasali

where is the code of your second snippet ?

stof avatar Aug 07 '24 14:08 stof

it's in the datatable.js

kasali avatar Aug 07 '24 21:08 kasali

@stof do you find a solution for me?

kasali avatar Aug 13 '24 10:08 kasali

I don't have an idea.

Would it be possible to create a reproducing case for the issue (i.e. a small Symfony project in which this error happens while using the minimal amount of code for that, which we could run to investigate as well) ?

stof avatar Aug 13 '24 11:08 stof