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 🙏

© 2026 – Pkg Stats / Ryan Hefner

use-translation

v1.1.14

Published

A React Hook for Language Translation

Downloads

6

Readme

React -- use-translation

A Language Translation for React.

Feature Includes:

  • A Simple but Powerful Translate what just a single function call
  • Support TypeScript with complete definition file
  • Easy to write your own Translations for multi-languages
  • Easy to attach to any React Components
  • Support Font toggling

Installation and Usage

The easiest way to use use-translation

npm install --save use-translation
// or
yarn add use-translation

Create your Translation File

const TRANSLATION = {
  // language,
  en: {
    //key: value
    hello_world: 'Hello World'
  },
  zh: {
    hello_world: '你好, 世界'
  }
}

Then use it in your app:

Add Your Font File

We only accept className as value;

const FONT = {
  // key: className
  en: 'roboto',
  zh: 'sans-serif'
}

Add Your Font Class in CSS / SASS / LESS / more

.roboto {
  font-family: roboto, sans-serif !important;
}

.sans-serif {
  font-family: sans-serif !important;
}

At your root component:

import React from 'react';
import { TranslationProvider, useTranslate } from 'use-translation';

import TRANSLATION from 'translation/file';

import FONTS from 'translation/font';
import './path/to/font/css/file.scss/.less/.css';

export const MyApp = () => {
  return (
    <TranslationProvider fonts={FONTS} translation={TRANSLATION}>
      <App />
    </TranslationProvider>
  )
}

const App = () => {
  const { changeLanguage, translate, language } = useTranslate();

  const handleClick = () => {
    if(language === 'zh') {
      setLanguage('en');
      return;
    }

    setLanguage('zh');
    return;
  }

  return (
    <>
      <h1>
        Current Language: {language}
      </h1>

      <button onClick={handleClick}>Toggle Language</button>

      <h2>My First Translation</h2>
      <p>{translate('hello_world')}</p>
    </>
  )
}

Props

TranslationProvider:

  • translation - Object that contains translation of different language
  • initialLanguage - String that will be set when the Provider mount

Methods

  • useTranslate() - returns current language, set language function and translate function
  • changeLanguage() - accepts string as parameter and change the current language
  • translate() - accepts string as key to look for value in translation props passed to TranslationProvider Component

License

MIT licensed. Copyright (c) Jamyth Luk 2020.