国际化

GitBook内置了对国际化的支持。 插件可以注册新语言,并为不同语言提供正确的消息。

注册区域设置和消息

第一步是注册语言:

module.exports = GitBook.createPlugin({
    init: (dispatch, getState, { I18n }) => {
        dispatch(I18n.registerLocale('en-US', {
            MY_PLUGIN_MESSAGE: 'Hello World'
        }));
    }
});

在组件中显示

GitBook.connect添加了一个i18n prop来访问国际化:

const GitBook = require('gitbook-core');
const { React } = GitBook;

const MyButton = React.createClass({
    propTypes: {
        i18n: GitBook.Shapes.i18n
    },

    render() {
        const { i18n } = this.props;

        return (
            <GitBook.Button>
                {i18.t('MY_PLUGIN_MESSAGE')}
            </GitBook.Button>
        );
    }
});

module.exports = GitBook.connect(MyButton);
作者: 雪之梦技术驿站
链接: https://snowdreams1006.github.io/gitbook-official/zh/api/i18n.html
来源: 雪之梦技术驿站
本文原创发布于「雪之梦技术驿站」,转载请注明出处,谢谢合作!

https://snowdreams1006.github.io/snowdreams1006-wechat-open.png

results matching ""

    No results matching ""