Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic installation with script tags #356

Open
tacman opened this issue May 10, 2024 · 8 comments
Open

Basic installation with script tags #356

tacman opened this issue May 10, 2024 · 8 comments

Comments

@tacman
Copy link
Contributor

tacman commented May 10, 2024

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 tacman changed the title Example with Stimulus Basic installation with script tags May 10, 2024
@kasali
Copy link

kasali commented Aug 6, 2024

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

@tacman
Copy link
Contributor Author

tacman commented Aug 6, 2024

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.

@stof
Copy link
Contributor

stof commented Aug 6, 2024

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

@kasali
Copy link

kasali commented Aug 7, 2024

@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'),
      },
  },
});

@stof
Copy link
Contributor

stof commented Aug 7, 2024

where is the code of your second snippet ?

@kasali
Copy link

kasali commented Aug 7, 2024

it's in the datatable.js

@kasali
Copy link

kasali commented Aug 13, 2024

@stof do you find a solution for me?

@stof
Copy link
Contributor

stof commented Aug 13, 2024

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) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants