@jswork/react-ant-i18n
TypeScript icon, indicating that this package has built-in type declarations

1.1.13 • Public • Published

react-ant-i18n

I18n for antd.

version license size download

installation

npm install -S @jswork/react-ant-i18n

usage

  1. import css
@import "~@jswork/react-ant-i18n/dist/style.css";

// or use sass
@import "~@jswork/react-ant-i18n/dist/style.scss";

// customize your styles:
$react-ant-i18n-options: ()
  1. import js
import React, { useState } from 'react';
import { useIntl } from '@jswork/react-ant-i18n';
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.

Dependencies (6)

Dev Dependencies (51)

Package Sidebar

Install

npm i @jswork/react-ant-i18n

Homepage

js.work

Weekly Downloads

13

Version

1.1.13

License

MIT

Unpacked Size

13.9 kB

Total Files

14

Last publish

Collaborators

  • afeiship
  • yujiao.luo