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

reactlang.js

v1.0.22

Published

React.js localization component highly inspired by Laravel's Lang

Downloads

6

Readme

reactlang.js – React.js localization component based on Laravel's Lang and integrating Lang.js.

Build Status npm version codecov Laravel 5.5 Laravel 5.0 Hex.pm

Installation

Different installation methods:

Documentation

How to Use

const lang = {
    common: {
        hello_world: 'Hello, world!'
    }
};

<Translatable
    lang={lang}
    content={{
        transKey: 'common.hello_world'
    }}
/>

Will render the following:

<span>Hello, world!</span>

With children

const lang = {
    common: {
        first_name: 'First name'
    }
};

<Translatable
    lang={lang}
    attributes={{
        placeholder: {
            transKey: 'common.first_name'
        }
    }}
>
    <input type="text" />
</Translatable>

Will render the following:

<input type="text" placeholder="First name" />

Messages source format

The messages source format should look like the following:

{
    name: {
        key1: 'value1',
        key2: 'value2',
        // ... and more key-value pairs.
    },
    name: {
        key1: 'value1',
        key2: 'value2',
        // ... and more key-value pairs.
    },
    // ... and more locales.
}

Properties

The component MUST receive the lang property AND either a content property OR an attributes property.

You can also add a reference property that accepts a function that will receive the translated string.

This is handy for using the translated string outside of the render method.

e.g.

class HelloWorld extends Component {
    bindTranslation = translatedString => {
        this.translation = translatedString;
    }

    render() {
        return (
            <div>
                <Translatable
                    lang={lang}
                    content={{
                        transKey: 'common.hello_world'
                    }}
                    reference={this.bindTranslation}
                />
            </div>
        );
    }
}

lang (Required)

An object matching the Messages source format like below:

{
    common: {
        home: 'Home',
        about: 'About',
        contact: 'Contact'
    },
    search: {
        filter: 'Filter',
        price_range: 'Price Range'
    }
}

content (Optional)

An object containing any of the following properties (transKey is required):

{
    transKey: 'common.people_lower',
    count: 5,
    replacements: {
        number: 5
    }
}

attributes (Optional)

An object with element attributes as keys with object values containing the same properties as the content property (transKey is required):

{
    placeholder: {
        transKey: 'common.select'
    }
}

id (Optional)

An id to be applied to the span rendered by the component when no children are present.

className (Optional)

A class name string.

handleError (Optional)

A function for handling errors. Receives an object like the following:

{
    message: 'The Translatable component only allows a single child',
    name: 'Too many children'
}

Development

  1. Fork this repository and clone it.
  2. Create a branch from develop: git checkout -b feature/xxxxxxx
  3. Submit a PR to be merged into develop branch.

Testing

To run the tests use the following commands:

  • Single run: npm run test
  • Run on changes: npm run test:watch

License

FOSSA Status