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

react-i18n-viz

v1.0.0

Published

Visualization of i18n-strings for react

Downloads

10

Readme

react-i18n-viz

Visualization of i18n-strings, inspired by railslove/i18n_viz.

...or view the Demo.

In developoment.

This Library provides a Higher-Order Component to wrap around i18n Components. If you hover over such a Component, a Tooltip will be visible with the id and description of the i18n String. This is very useful if you want to check in your Browser which String belongs to which id.

It also includes support for popular i18n Libraries:

Those Components are simply the Components of their Libraries, wrapped with the HOC.

It has nearly no impact on the size of your bundle in Production (or other environments, where the visualization should not be visible). If it isn't used, it won't be bundled.

Usage

react-i18n-viz is turned off by default. This prevents that the tooltips are visible in environments, which you don't specify. To enable the Tooltips add a special Environment Variable:

REACT_APP_SHOW_I18N_VIZ=true

You can find a working App in /example.

with react-intl

Instead of importing FormattedMessage and FormattedHTMLMessage from react-intl, import them from react-i18n-viz/lib/react-intl. You can use those components like their react-intl counterparts.

import React from 'react'
import { IntlProvider } from 'react-intl'
import { FormattedMessage } from 'react-i18n-viz/lib/react-intl'

export default class MyComponent extends React.Component {
  render() {
    return (
      <IntlProvider locale="en" messages={/* ... */}>
        <div>
          <FormattedMessage
            id="app.greeting"
            description="A friendly greeting."
            values={{ name: 'John' }}
          />
        </div>
      </IntlProvider>
    )
  }
}

with react-i18next

Instead of importing Trans from react-i18next, import it from react-i18n-viz/lib/react-i18next. You can use it like the Trans-Component from react-i18next.

To show a description in the i18n-viz Tolltip, you can provide the description prop.

import React from 'react'
import { I18nextProvider } from 'react-i18next'
import { Trans } from 'react-i18n-viz/lib/react-i18next'

export default class MyComponent extends React.Component {
  render() {
    return (
      <I18nextProvider i18n={i18n}>
        <div>
          <Trans i18nKey="app_greeting" description="A friendly greeting.">
            Hello {{ name }}, how are you today
          </Trans>
        </div>
      </I18nextProvider>
    )
  }
}

as Higher-Order Component

Example

import { withI18nViz } from 'react-i18n-viz'

class MyCustomI18nComponent {
  static propTypes = {
    myI18nId: PropTypes.string,
    myI18nDescription: PropTypes.string
  }

  // ...
}

const mapVizProps = props => ({
  id: props.myI18nId, // required
  description: props.myI18nDescription // optional
})

export default withI18nViz(mapVizProps)(MyCustomI18nComponent)

withI18nViz(mapVizProps)

Enhances a React Component with the i18n visualization.

  • mapVizProps (Function). Defines which of your props are used as i18n id and as i18n description. Needs to return an object with { id, description }.

Contribute

  1. Clone repo
  2. npm install
  3. npm link && cd example && npm link react-i18n-viz
  4. Run npm start to bundle the library in dev mode
  5. Run cd example && npm start in a separate shell to start the example app

License

MIT © 2018 - present, Railslove GmbH.

Made for you with 💚 by Railslove.