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

@kano/kbc-intl

v2.0.13

Published

> TODO: description

Downloads

20

Readme

kbc-intl

Components and functions to provide the ability to add different locales to apps.

The language provider should sit at the top level of your app and can take in the following props.

Props

  • locale: string - The current locale, this can be a 2 (fr) or 5 (en-US) character language specifier
  • messages?: LocaleMessages - The apps loaded translated messages object compiled by the apps i18n.js file located at ./src/i18n.js;

Usage

import LanguageProvider from '@kano/kbc-intl';
import { translationMessages } from './i18n';

<LanguageProvider locale="de" messages={translationMessages}>
    <App />
</LanguageProvider>

defineMessages()

Defines a components locale messages.

Usage

For a given component if this component requires translations you should create a messages.ts within that components directory which would include the below message definitions.

I.e. ./src/components/Navbar/messages.ts;

import { defineMessages } from 'react-intl';

export const scope = 'components.Navbar';

export default defineMessages({
  challenges: {
    id: `${scope}.home`,
    defaultMessage: 'Home',
  },
  userProfile: {
    id: `${scope}.userProfile`,
    defaultMessage: 'Made with love by {user}.',
  }
});

Rendering intl messages within components/containers

Using the FormattedMessage component will display a given message from your messages.ts file in the selected current active language.

You will also notice a more complex use of FormattedMessage for the author message where alternate or variable values (i.e. author: <A href="https://twitter.com/mxstbr">Max Stoiber</A>,) are being injected, in this case it's a react component.

import React from 'react';

import messages from './messages';
import A from 'components/A';
import styles from './styles.css';
import { FormattedMessage } from 'react-intl';

function Navbar() {
  return (
    <nav className={styles.footer}>
      <section>
        <p>
          <FormattedMessage {...messages.Home} />
        </p>
      </section>
      <section>
        <p>
          <FormattedMessage
            {...messages.userProfile}
            values={{
              user: <A href="https://twitter.com/00Jams">Jams Bond</A>,
            }}
          />
        </p>
      </section>
    </nav>
  );
}

export default Navbar;

injectIntl()

Another way to render messages is by using a higher order component to pass intl object to props and then use the intl.formatMessage to pass messages as string props to components, see below for example:

import React, { Component } from 'react';
import { injectIntl, IIntlShape, IInjectIntlChildProps } from 'react-intl';

import messages from './messages';
import { NavbarItem } from './NavLink';

// Pass types via the shape
interface NavbarProps {
    intl: IIntlShape;
}

// Or Extend using the IInjectIntlChildProps
interface NavbarProps extends IInjectIntlChildProps {}

class NavbarC extends Component<NavbarProps> {
    render() {
        const { intl } = this.props;

        return (
              <div className="navbar">
                  <div className="row">
                      <div className="navbar__children">
                          <NavbarItem text={intl.formatMessage({...messages.home})} />
                      </div>
                  </div>
              </div>
        );
    }
}

export const Navbar = injectIntl(NavbarC);