npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

i18nize-react

v0.11.0

Published

A babel plugin cli to automatically internationalize any react app

Downloads

127

Readme

i18nize-react

Internationalize legacy react apps in a lunch break.

i18nize-react finds and replaces all the hardcoded string literals in your react project with i18n bindings. It uses babel to walk on react components and process them.

diff

Getting started

  1. First install the i18nize-react globally using npm
npm i -g i18nize-react
  1. Now in your react app run
npm install i18next

Tested on i18next other variants should work with minor changes.

Make sure there are no unstaged changes, you may need to git reset --hard.

  1. Now run.
i18nize-react
  1. Go for lunch

  2. Run your favourite linter to clean things up.

  3. It should create four files src/i18n/init.js, src/i18n/keys.js, src/i18n/english.js, src/i18n/chinese.js. Add the line import ./i18n/init.js; in your App's entry point. Usually it is src/index.js.

  4. Change the lng key in your browser's local storage to see changes.

Contributions

Create an issue ticket with a before and after code snippets, before writing any code and raising a PR.

For bugs create a minimum reproducible piece of code with original, received and expected snippets.

Make sure to read wont-fix.md.

Troubleshooting

  1. Sometimes i18ize-react might conflict with the babel plugins installed in your project. If that happens go up one folder (cd ..) and then run i18ize-react ./your-dir ./your-dir

  2. By default i18ize-react assumes that your code is in <your workspace dir>/src but if you want to change that you can use the third argument. e.g. i18ize-react ./ ./ web will crawl <your workspace dir>/web instead.

  3. Constant initialization outside react lifecycle is not guaranteed. To resolve this, move all initialized strings inside the component.

// String 1 might not load correctly 
const string1 = i18next.t(k.STRING1);
const MyComponent = () => {
  // String 2 will load correctly
  const string2 = i18next.t(k.STRING2);

  return (
    <div>
      {string1}
      {string2}
    </div>
  )
}
  1. TIP: Babel's parse and generate often shifts code around which causes files, with no programatic change, to show up in git diff. Sometimes running the linter alone does not fix this problem. A good way to fix this problem is to do a dry run i18nize-react ./ ./ src true, run your linter and commit the code. Now run i18nize-react to run the transform and lint again. Now only the transformed changes should show up in git diff.