How can I load the language files dynamically with webpack?
import validate from 'jquery-validation'
import 'jquery-validation/dist/localization/messages_de'
import 'jquery-validation/dist/localization/methods_de'
I could do something like
let lang = 'de'
import('jquery-validation/dist/localization/messages_' + lang)
But how is webpack resolving this? I guess I have to define somewhere all possible combinations?
This is my solution so far
var lang = "{{ set_current_lang_here }}";
switch(lang) {
case 'de':
import('jquery-validation/dist/localization/messages_de');
break;
case 'pl':
import('jquery-validation/dist/localization/messages_pl');
break;
....
}
But it feels hacky, because I have to enter all languages by hand.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.