This is a modified version of examples/app-npm-webpack from globalize 1.4.0 that allows the user to change the locale, then dynamically loads aditional localize converters and messages. Click here to try it out
This version uses webpack 4. It does not use globalize-webpack-plugin but instead, uses skip-amd-webpack-plugin and loads localization data through cldr.
Dynamic loading is done by src/globalize/LocaleDataLoader.js
. You may need to adapt it so suit the needs of your own application.
Other versions of this example are available that combine globalize.js with react.js and react-widgets:
The version for webpack 4 using globalize-webpack-plugin 3 currently does not work due to a bug in globalize-webpack-plugin
1. Install the app
git clone https://github.com/metaclass-nl/switch-language-example-globalize.git
Or download the zip file from github and extract all.
2. Install app development dependencies
This example uses npm
to download the app development dependencies (i.e.,
Globalize, CLDR data, Cldrjs, Webpack, [Globalize Webpack Plugin][], and
others).
npm install
npm start
npm start
, which uses webpack's live reload HMR
(Hot Module Replacement). See package.json
to understand the actual shell
command that is used. See webpack-config.js
for how the plugins are confgured.Dynamic loading of localization data is done directly from node_modules subfolders and the messages folder.
npm run build
npm run build
, which will be
created at ./build
. The localization data is copied by copy-webpack-plugin.
See package.json
to understand the actual shell command that is used.
See webpack-config.js
for how the plugins are confgured../build/index.html
to run the application using the
generated production files. Edit this file to display the application using a
different initial locale (source code has instructions). Change App const initialLocale accordingly.