diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-10-01 14:14:30 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-10-01 14:14:30 +0200 |
commit | da83d9e91d419e1c843e3017098d25dbde22b500 (patch) | |
tree | 0cf3860171062794ef66a292f46fdd62e66dc780 /docs/api | |
parent | 2cf507a807b1070a445cadb28317a41385fbe50b (diff) | |
download | gitbook-da83d9e91d419e1c843e3017098d25dbde22b500.zip gitbook-da83d9e91d419e1c843e3017098d25dbde22b500.tar.gz gitbook-da83d9e91d419e1c843e3017098d25dbde22b500.tar.bz2 |
Change api for registering components
Diffstat (limited to 'docs/api')
-rw-r--r-- | docs/api/i18n.md | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/docs/api/i18n.md b/docs/api/i18n.md new file mode 100644 index 0000000..026a2d5 --- /dev/null +++ b/docs/api/i18n.md @@ -0,0 +1,44 @@ +# Internationalize your plugin + +GitBook has built-in support for internationalization. Plugins can register new languages and provide the right messages for different languages. + +### Register locale and messages + +The first step is to register messages for a language: + +```js +module.exports = GitBook.createPlugin({ + init: (dispatch) => { + dispatch(GitBook.registerLocale('en-US', { + MY_PLUGIN_MESSAGE: 'Hello World' + })); + } +}); +``` + +### Render a message in a component + +`GitBook.connect` adds a `i18n` prop to access the internationalization: + +```js +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); +``` |