Coder Social home page Coder Social logo

react-intl-loader's Introduction

react-intl-loader

Async react-intl locale data loader for webpack.

Motivation

Instead of needing a long utility function with a require.ensure for every locale, you can write something like this:

// ES6 syntax

const locales = {
  en: () => require('react-intl?locale=en!./en.json'),
  de: () => require('react-intl?locale=de!./de.json')
}

function loadLocaleData (locale) {
  return new Promise((resolve) => {
    locales[locale]()(resolve)
  })
}

loadLocaleData(someLocale).then((messages) => {
  // do something with messages
})

Installation

$ npm install --save intl intl-locales-supported react-intl
$ npm install --save-dev react-intl-loader

Usage

Documentation: Using loaders

To asynchronously load your locale data from ./en.json with the locale en, use:

require('react-intl?locale=en!./en.json')(function (messages) {
  // messages contains the require of ./en.json
});

This will asynchronously require (via webpack's require.ensure) the following modules:

'intl/locale-data/jsonp/en' // Optional: only if Intl does not support this locale
'react-intl/locale-data/en'
'./en.json'

You can use any file and file type for your locale data as long as you have the appropriate webpack loader installed and configured.

react-intl-loader's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-intl-loader's Issues

Define use default

Hi. Is there a way to define that when using locale en-GB and en-US that it should then use the default translations? It works when i dont define a locale function for it, but gets error messages "app.js:1032 [React Intl] Missing message: "app.language.language" for locale: "en-GB", using default message as fallback."

Do i need to create a en.json where i whitelist all the words or can i say that i just want to use the defaults?

Locale Normalization

How do you handle locale-normalization? For example if you've defined that you support en and fr and the current locale is en-CA the current example will fail.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.