1.0.2 ā€¢ Published 5 years ago

next-i18n-keys v1.0.2

Weekly downloads
18
License
MIT
Repository
github
Last release
5 years ago

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 475212506@qq.com

šŸ¤ 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 <475212506@qq.com>. This project is MIT licensed.