Skip to content

maciejw/react-intl-namespaces

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
Maciej Warszawski
Mar 9, 2018
ec2aab8 · Mar 9, 2018

History

48 Commits
Feb 28, 2018
Feb 16, 2018
Feb 18, 2018
Mar 9, 2018
Feb 28, 2018
Feb 18, 2018
Jan 23, 2018
Feb 16, 2018
Feb 12, 2018
Feb 13, 2018
Jan 30, 2018
Feb 13, 2018
Feb 6, 2018
Feb 28, 2018
Feb 18, 2018
Feb 8, 2018
Feb 18, 2018
Feb 28, 2018
Feb 28, 2018
Feb 28, 2018
Feb 18, 2018
Feb 28, 2018
Feb 16, 2018
Feb 16, 2018
Feb 16, 2018
Feb 18, 2018
Feb 18, 2018
Feb 18, 2018
Feb 13, 2018
Feb 28, 2018
Feb 28, 2018
Feb 28, 2018

Repository files navigation

React Intl Namespaces

Integrations of react-intl internationalization library with locize.com online translation service.

build-status-icon npm-react-intl-namespaces-version-icon npm-react-intl-namespaces-locize-client-version-icon npm-react-intl-namespaces-locize-editor-version-icon

Goals of this library

  • add support of dividing your application resources into namespaces that can be lazy loaded from server
  • make resources statically typed
  • add support of locize.com in-context editor.
  • add resource synchronization with locize.com or any other backend.

Getting started

const someNamespace = defineMessages<'property1'>({
  property1: {
    defaultMessage: 'text with {someValue}',
    description: 'description of text with some value',
    id: 'property1',
  },
});

const anotherNamespace = defineMessages<'property1'>({
  property1: {
    defaultMessage: 'another text',
    description: 'description of another text',
    id: 'property1',
  },
});

const values = { someValue: 'value' };

const App = (props: IntlBackendProvider.Props) => (
  <IntlBackendProvider
    locale={props.locale}
    showIds={props.showIds}
    getMessagesFromNamespaceFactory={props.getMessagesFromNamespaceFactory}
    addMissingMessageFactory={props.addMissingMessageFactory}
  >
    <IntlNamespaceProvider namespace="someNamespace">
      <div>
        <FormattedMessage {...someNamespace.property1} values={values} />
      </div>
    </IntlNamespaceProvider>
    <IntlNamespaceProvider namespace="anotherNamespace">
      <div>
        <FormattedMessage {...anotherNamespace.property1} />
      </div>
    </IntlNamespaceProvider>
  </IntlBackendProvider>
);

This code uses two namespaces and provides a way of communication with backed using getMessagesFromNamespace and addMissingMessage API.

Namespaces have have the same resource keys, that do not interfere with each other.

Those namespaces could be application modules.

Also we can see with one switch resource keys instead of resource texts when we set showIds to true. This is what will be displayed

[someNamespace:property1 (someValue)]

instead of formatted

text with value

Building

In order to build this library you have to clone it

git clone https://github.com/maciejw/react-intl-namespaces.git

and restore packages with

yarn

to show sample integration project you can

yarn start

you can also test with

yarn test

Documentation

//TODO

About

Integrations of react-intl internationalization library with locize.com online translation service.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published