next-i18n-keys
v1.0.2
Published
auto generate next page's i18n keys
Downloads
9
Readme
Auto generate next.js page's i18n keys
🏠 Homepage
Install
yarn install
Configuration
// next.config.js
const NextI18nKeysWebpackPlugin = require('next-i18n-keys');
// ...
config.plugins.push(
// ...
new NextI18nKeysWebpackPlugin({
// RegExp of placeholder in source file
matchReg: /'\^__I18N_KEYS__\$'/,
funcList: ['i18next.t', 'i18n.t'],
}),
// ...
);
// ...
// pages/*.js
Page.getInitialProps = async () => {
// a object of i18n data
const data = await fetch('https://...');
// placeholder of keys, will be replaced by plugin
const keys = '^__I18N_KEYS__$';
const i18n = keys.reduce((obj, key) => (obj[key] = data[key], obj), {});
return {
i18n,
};
}
Author
👤 Sora Liu [email protected]
- Github: @lovesora
🤝 Contributing
Contributions, issues and feature requests are welcome!Feel free to check issues page.
Show your support
Give a ⭐️ if this project helped you!
📝 License
Copyright © 2019 Sora Liu [email protected]. This project is MIT licensed.