New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-simple-i18n

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-simple-i18n - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

LICENSE

5

lib/create-i18n.js

@@ -32,2 +32,6 @@ "use strict";

function getLang() {
return currentLang;
}
function setLang(lang) {

@@ -48,2 +52,3 @@ if (lang === currentLang) return;

t: t,
getLang: getLang,
setLang: setLang,

@@ -50,0 +55,0 @@ listen: listen,

2

package.json
{
"name": "react-simple-i18n",
"version": "0.1.0",
"version": "0.1.1",
"description": "React i18n solution with context API",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

# React Simple I18n
- React i18n solution with context API
- React i18n solution with context API, support React 16.3.0+
- Simple usage, easy to configure
## Usage
```jsx
import React, { Component } from 'react'
import { render } from 'react-dom'
import { createI18n, I18nProvider, withI18n } from 'react-simple-i18n'
const langData = {
enUS: {
projects: 'Projects',
},
zhCN: {
projects: '项目',
},
}
class Demo extends Component {
handleSetEnglish = () => {
this.props.i18n.setLang('enUS')
}
handleSetChinese = () => {
this.props.i18n.setLang('zhCN')
}
render() {
const { t } = this.props
return (
<div>
<p>{t('projects')}</p>
<button onClick={this.handleSetEnglish}>English</button>
<button onClick={this.handleSetChinese}>中文</button>
</div>
)
}
}
const DemoWithI18n = withI18n(Demo)
const App = () => (
<I18nProvider i18n={createI18n(langData, { lang: 'enUS' })}>
<DemoWithI18n />
</I18nProvider>
)
render(<App />, document.getElementById('app-root'))
```
## Top Level API
### createI18n(data, options)
Creates an `i18n` object for `I18nProvider`
#### Arguments
- `data` Language data object, see usage above
- `options`
- `lang` Initial language to use
#### Return
- `i18n`
- `t` Get translation by language name
- `getLang` Get current language
- `setLang` Set language by language name
- `listen` Add listener to language change
- `unlisten` Unbind a listener of language change
### \<I18nProvider i18n\>
Makes `i18n` available to `withI18n` HOC
#### Props
- `i18n`: I18n object created by `createI18n`
### withI18n(Component)
Connects a React component to `i18n` object.
Adds `t` and `i18n` to props of wrapped component.
# License
MIT

@@ -24,2 +24,6 @@ let langData

function getLang() {
return currentLang
}
function setLang(lang) {

@@ -39,2 +43,3 @@ if (lang === currentLang) return

t,
getLang,
setLang,

@@ -41,0 +46,0 @@ listen,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc