jQuery-QueryBuilder icon indicating copy to clipboard operation
jQuery-QueryBuilder copied to clipboard

Fixed i18n translation files with ESM and vite.

Open mikevandiepen opened this issue 9 months ago • 1 comments

Merge request checklist

  • [x] I read the guidelines for contributing
  • [x] I created my branch from dev and I am issuing the PR to dev
  • [x] 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 avatar Apr 28 '25 11:04 mikevandiepen

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;
    });
}

mikevandiepen avatar May 07 '25 12:05 mikevandiepen