Skip to content

Conversation

mikevandiepen
Copy link

@mikevandiepen mikevandiepen commented Apr 28, 2025

Merge request checklist

  • I read the guidelines for contributing
  • I created my branch from dev and I am issuing the PR to dev
  • I didn't pushed the dist directory
  • If it's a new feature, I added the necessary unit tests
  • If it's a new language, I filled the __locale and __author fields

🗒️ There where issues where jquery wasn't globally accessible when initializing jquery-builder, adding window.$ solved the problem. i18n files cannot be imported using ESM and vite.

@mikevandiepen mikevandiepen changed the title Couldn't access globally defined jquery instance when using vite Fixed i18n translation files with ESM and vite. Apr 28, 2025
@mikevandiepen
Copy link
Author

We could hack around it using this approach.

import nl_lang from './../../../node_modules/jQuery-QueryBuilder/src/i18n/nl.json';
import fr_lang from './../../../node_modules/jQuery-QueryBuilder/src/i18n/fr.json';
import es_lang from './../../../node_modules/jQuery-QueryBuilder/src/i18n/es.json';
import de_lang from './../../../node_modules/jQuery-QueryBuilder/src/i18n/de.json';

if (window.$) {
    let fnQueryBuilderImport = import('jQuery-QueryBuilder/dist/js/query-builder');

    fnQueryBuilderImport.then(function() {
        window.$.fn.queryBuilder.regional['nl'] = nl_lang;
        window.$.fn.queryBuilder.regional['fr'] = fr_lang;
        window.$.fn.queryBuilder.regional['es'] = es_lang;
        window.$.fn.queryBuilder.regional['de'] = de_lang;
    });
}

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

Successfully merging this pull request may close these issues.

1 participant