1.1.15 • Published 9 months ago
@jswork/react-i18n v1.1.15
react-i18n
I18n for react project.
installation
npm install -S @jswork/react-i18n
usage
import css
@import "~@jswork/react-i18n/dist/style.css"; // or use sass @import "~@jswork/react-i18n/dist/style.scss"; // customize your styles: $react-i18n-options: ()
import js
import React, { useState } from 'react'; import { useIntl } from '../../src/main'; import styled from 'styled-components'; import { Select, Space, Table, DatePicker, TimePicker, Avatar, Button, Modal } from 'antd'; // import nx from '@jswork/next'; const Container = styled.div` .ant-avatar { margin: 10px 0; } `; const items = [ { value: 'en-US', label: 'English' }, { value: 'zh-CN', label: '中文' } ]; export default () => { const { t, i18n } = useIntl(); const [visible, setVisible] = useState<boolean>(false); // inject as global for debug // nx.t = t; // nx.i18n = i18n; const img = i18n.language === 'zh-CN' ? '5' : '1'; return ( <Container> <div className="App"> <header className="App-header"> <Space> <Avatar src={`https://randomuser.me/api/portraits/lego/${img}.jpg`} size={120} /> <Select value={i18n.language} style={{ width: 120 }} onChange={(value) => i18n.changeLanguage(value)} options={items} /> </Space> <Space direction="vertical"> <h1 style={{ color: '#fff' }}>{t('key')}</h1> <p dangerouslySetInnerHTML={{ __html: t('desc', { interpolation: { escapeValue: false } }) }} /> <Table style={{ width: 600 }} dataSource={[]} /> <Space> {/* @ts-ignore */} <DatePicker /> <TimePicker /> <Button type="primary" onClick={() => setVisible(true)}> {t('open-a-modal')} </Button> </Space> </Space> </header> <Modal open={visible} onOk={() => setVisible(false)} onCancel={() => setVisible(false)}> {t('mtxt')} </Modal> </div> </Container> ); };
preview
license
Code released under the MIT license.
1.1.15
9 months ago
1.1.1
10 months ago
1.0.17
10 months ago
1.0.16
10 months ago
1.1.9
10 months ago
1.1.8
10 months ago
1.1.7
10 months ago
1.1.6
10 months ago
1.1.5
10 months ago
1.1.4
10 months ago
1.1.3
10 months ago
1.1.2
10 months ago
1.1.12
9 months ago
1.1.11
10 months ago
1.1.10
10 months ago
1.1.14
9 months ago
1.1.13
9 months ago
1.0.14
10 months ago
1.0.11
1 year ago
1.0.10
1 year ago
1.0.13
1 year ago
1.0.12
1 year ago
1.0.9
2 years ago
1.0.8
2 years ago
1.0.7
2 years ago
1.0.6
2 years ago
1.0.5
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago