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

translation-service-fe-lib

v0.1.0

Published

`translation-service-fe-lib` is a lightweight React library that provides a simple and efficient solution for managing translations in your React applications. It handles translations using a React context and custom hooks, making it easy to integrate int

Readme

translation-service-fe-lib README

translation-service-fe-lib is a lightweight React library that provides a simple and efficient solution for managing translations in your React applications. It handles translations using a React context and custom hooks, making it easy to integrate into your projects.

Installation

To install this library, you can use the following command:

npm install translation-service-fe-lib

Usage

To use the library, you'll need to import and utilize the TranslationsProvider component and the useTranslations custom hook in your React application.

Setting up the TranslationsProvider

Wrap your application's root component with the TranslationsProvider component, and pass the required properties:

import { TranslationsProvider } from 'translation-service-fe-lib';

// Your translations dictionary
const translationsDictionary = {...};

// Your app language key
const appLanguage = 'your-app-language-key';

// Your language configuration
const languageConfig = {...};

// Your custom translation handler implementing the ITranslationHandler interface
const translationHandler = new CustomTranslationHandler();

ReactDOM.render(
  <TranslationsProvider
    translationsDictionary={translationsDictionary}
    appLanguage={appLanguage}
    languageConfig={languageConfig}
    translationHandler={translationHandler}
  >
    <App />
  </TranslationsProvider>,
  document.getElementById('root')
);

Using the useTranslations hook

To access the translation functions in your components, import and use the useTranslations custom hook:

import { useTranslations } from 'translation-service-fe-lib';

function MyComponent() {
  const { translate, currentLanguage, setCurrentLanguage } = useTranslations();

  // Example usage
  const translatedText = translate('module.exampleLabel', { param1: 'value1' });

  return (
    <div>
      <p>{translatedText}</p>
    </div>
  );
}

API

TranslationsProvider

This component provides the translations context to your React application. It accepts the following properties:

  • children: The React component(s) to render.
  • translationsDictionary: The translations dictionary object.
  • appLanguage: A unique key to store the user's selected language in the localStorage.
  • languageConfig: The language configuration object, containing information about the available languages and the default language.
  • translationHandler: A custom translation handler implementing the ITranslationHandler interface, responsible for fetching, storing, and loading translations.

useTranslations

This custom hook allows you to access the translation functions in your components. It returns an object containing the following properties:

  • translate: A function that accepts a translation key and an optional object with parameters, and returns the translated text for the current language.
  • currentLanguage: A string representing the current language code.
  • setCurrentLanguage: A function that accepts a new language code and updates the current language.

Commands

The following npm commands are available in this package:

1. build:pre

This command renames the node_modules_backup folder to node_modules. It's useful to restore the node_modules folder before building the project, in case it was backed up previously.

npm run build:pre

2. build

This command compiles your TypeScript files using the TypeScript compiler (tsc). The configuration is read from the tsconfig.json file in your project directory.

npm run build

3. build:after

This command renames the current node_modules folder to node_modules_backup. It's useful for backing up the node_modules folder after the build process to prevent unnecessary dependencies from being included in your deployment package.

npm run build:after

4. build:all

This command runs all of the above commands in sequence: build:pre, build, and build:after. It's a convenient way to run the entire build process with a single command. Used for local development (using npm-link) in order to not include node_modules folder

npm run build:all

Use of build commands:

  • initial use (when you build the library for first time you should install all the packages which will create node_modules folder, build the library and rename node_modules folder to node_modules_backup):
npm install
npm run build
npm run build:after
  • common use (when you usually build the library you should use npm run build:all in order to rename node_modules_backup folder to node_modules, build the library and again rename node_modules folder to node_modules_backup):
npm run build:all

Contributing

If you have any suggestions, improvements, or bug reports, please feel free to submit an issue or a pull request on the project's repository. Your feedback is highly appreciated!