LocaleProvider 国际化

    为组件内建文案提供统一的国际化支持。 LocaleProvider 使用 React 的 特性,只需在应用外围包裹一次即可全局生效。 我们暂时只提供英语,中文两种语言支持(),所有语言包可以在 这里 找到。 如果你找不到你需要的语言包,欢迎你在 的基础上创建一个新的语言包,并给我们 Pull Request。

    其他国际化需求

    本模块仅用于组件的内建文案,若有业务文案的国际化需求,建议使用 react-intl,可参考示例:Intl demo 2 Wrap your app with LocaleProvider, and apply the corresponding language package.
    1. import {
    2. Pagination, LocaleProvider, List, DatePicker, WhiteSpace, WingBlank, InputItem,
    3. Picker, SearchBar,
    4. } from 'antd-mobile';
    5. import enUS from 'antd-mobile/lib/locale-provider/en_US';
    6. import ruRU from 'antd-mobile/lib/locale-provider/ru_RU';
    7. const maxDate = new Date(2018, 11, 3, 22, 0);
    8. const minDate = new Date(2015, 7, 6, 8, 30);
    9. const seasons = [
    10. [
    11. {
    12. label: '2013',
    13. value: '2013',
    14. },
    15. {
    16. label: '2014',
    17. value: '2014',
    18. },
    19. ],
    20. [
    21. {
    22. label: '春',
    23. value: '春',
    24. },
    25. {
    26. label: '夏',
    27. value: '夏',
    28. },
    29. ],
    30. ];
    31. const Page = () => (
    32. <div>
    33. <WhiteSpace />
    34. <List
    35. style={{ backgroundColor: 'white' }}
    36. >
    37. <DatePicker
    38. mode="date"
    39. title="Select date"
    40. minDate={minDate}
    41. maxDate={maxDate}
    42. >
    43. <List.Item arrow="horizontal">datePicker</List.Item>
    44. </DatePicker>
    45. <Picker
    46. data={seasons}
    47. cascade={false}
    48. >
    49. <List.Item arrow="horizontal">picker</List.Item>
    50. </Picker>
    51. </List>
    52. <WhiteSpace />
    53. <SearchBar placeholder="Search" showCancelButton />
    54. <WhiteSpace />
    55. <InputItem type="money" placeholder="money input" />
    56. </div>
    57. );
    58. class App extends React.Component {
    59. constructor(props) {
    60. super(props);
    61. this.state = {
    62. locale: 'English',
    63. };
    64. }
    65. onChange = (value) => {
    66. this.setState({
    67. locale: value[0],
    68. });
    69. }
    70. render() {
    71. const languages = [
    72. {
    73. value: '中国',
    74. label: '中国',
    75. language: undefined,
    76. },
    77. {
    78. value: 'English',
    79. label: 'English',
    80. language: enUS,
    81. },
    82. {
    83. value: 'Русский',
    84. label: 'Русский',
    85. language: ruRU,
    86. },
    87. ];
    88. const currentLocale = languages.find(item => item.value === locale).language;
    89. return (
    90. <WingBlank>
    91. <Picker
    92. data={languages}
    93. onChange={this.onChange}
    94. cols={1}
    95. value={[locale]}
    96. >
    97. <List.Item arrow="horizontal">Choose language</List.Item>
    98. </Picker>
    99. <WhiteSpace size="xl" />
    100. <WhiteSpace size="xl" />
    101. <LocaleProvider locale={currentLocale}>
    102. <Page />
    103. </LocaleProvider>
    104. </WingBlank>
    105. );
    106. }
    107. }