Skip to content

Frontend internationalization component base React 🤤

Notifications You must be signed in to change notification settings

BertieGo/react-i18n

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-i18n

NPM JavaScript Style Guide

Frontend internationalization component base React

Language

Chinese

Usage

npm : npm install rc-i18n

yarn : yarn add rc-i18n

Examples

First, base on your language requirement to config i18n.json file, just like:

{
  "zh-CN": {
    "say_hi": "你好!"

  },
  "en-US": {
    "say_hi": "Hi!"
  }
}

In your code, import & usage:

import I18n, { injectAsyncI18n } from './rc-i18n';
// you need to inject i18n.json frist
injectAsyncI18n('TEST', require('./i18n'));

render() {
    <I18n  region={'TEST'} i18n="say_hi" />
}

API

  • getCurrentLanguage: (): CN-zh | en-US
    get current language in window locale

  • switchLanguage:(language: CN-zh | en-US): void
    switch language with CN-zh | en-US

  • get: (region: string, i18n: string, params: {[name]: string }) : string
    get local language value

NPM

rc-i18n

About

Frontend internationalization component base React 🤤

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published