Coder Social home page Coder Social logo

pkoson / react-intl-namespaces Goto Github PK

View Code? Open in Web Editor NEW

This project forked from maciejw/react-intl-namespaces

0.0 1.0 0.0 292 KB

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

License: MIT License

Batchfile 0.04% JavaScript 5.14% Shell 0.62% TypeScript 92.39% HTML 0.24% CSS 1.58%

react-intl-namespaces's Introduction

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

react-intl-namespaces's People

Watchers

Piotr avatar

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.