metaclass-nl / switch-language-example-globalize

An example of dynamically switching language using globalize.js and react-widgets aiming to be compatible with start-react-app.
Other
0 stars 0 forks source link

Switch language example with globalize.js and webpack 4

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

Requirements

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

Running the app

Development server

npm start
  1. Start a server by running 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.

Production build

npm run build
  1. Generate the compiled bundles by running 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.
  2. Point your browser at ./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.

Limitations