0

How to use the angular-dynamic-locale with webpack?

The angular-dynamic-locale always tries to load the angular-locale_en.js file from path http://localhost:8080/angular/i18n/angular-locale_de.js during the running-time, when the "tmhDynamicLocale.set('de');" is performed.

I'm using webpack therefore I define every dependencies either in the top of my app.js or in the top of my controllers. I tried to define this with require('angular-i18n/angular-locale_de') or with import, but unfortunatelly, I always get the following error messages:

GET http://localhost:8080/angular/i18n/angular-locale_de.js net::ERR_ABORTED 404 (Not Found)
Refused to execute script from 'http://localhost:8080/angular/i18n/angular-locale_de.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
matyig
  • 454
  • 5
  • 15

1 Answers1

1

If you use your locales like this:

tmhDynamicLocaleProvider
    .localeLocationPattern('./angular/i18n/angular-locale_{{locale}}.js')
    .defaultLocale('de');

You can probably use CopyWebpackPlugin like this:

new CopyWebpackPlugin([
    {from: './node_modules/angular-i18n/angular-locale_de.js', to: path.resolve(__dirname, '.[WEBPACK OUTPUT FOLDER]' + '/angular/i18n')}
])

Be sure that the destination folder matches the output of your webpacked files

Groben
  • 1,374
  • 2
  • 10
  • 29
  • what to do in case of dynamic locale based on condition? i want to add two locale file one for de and another for en – Palak Jadav Jan 17 '20 at 11:59