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

@translator-app/react

v0.1.0

Published

The translator app react library, is a react context that creates a `@translator-app/core` instance and adds some utilities on top to make it easier to use with react. Such as asynchronously loading translation files and simplifying the overall API of cor

Downloads

8

Readme

@translator-app/react

The translator app react library, is a react context that creates a @translator-app/core instance and adds some utilities on top to make it easier to use with react. Such as asynchronously loading translation files and simplifying the overall API of core into provider properties and callback functions.

Usage

To use this library you can import TranslatorProvider, useTranslator and/or TranslatorConsumer.

The Provider takes in the following properties:

// React child nodes
children: React.ReactNode;
// The currently displayed language
language: string;
// A language to fallback to, if non is defined it will fallback to the key name
fallbackLanguage?: string;
// An object that contains a library of translations with the key being the language key and value an object of translation templates
library?: RawTranslationLibrary;
// A function that gets called if it exists and the defined language does not exist in the library. It should return the translation file for that language
getTranslationRegistry?: (language: string) => Promise<RawTranslationRegistry> | RawTranslationRegistry;

Provider values (the values you receive when using useTranslator and/or TranslatorConsumer):

// The currently configured language, same as provided property...
language: string;
// A function to translate a key with an optional values field, values can be an object or array. Always returns a string.
translate: (key: string, values?: any) => string;
// The current version of the library, this is just a count of the amount of times getTranslationRegistry is called
version: number;

Example

import React from 'react';

const Example = () => {
  let { translate } = useTranslator();

  return <div>{translate('test', { name: 'Bob' })}</div>;
};

const App = () => {
  let { translationKey, values } = props;
  let { translate } = useTranslator();

  return (
    <TranslatorProvider
      language="nl"
      fallbackLanguage="en"
      library={{
        en: {
          test: 'This is a test value',
        },
      }}
      // This can also return a promise (or be an async function)
      getTranslationRegistry={(language) => {
        if (language !== 'nl') {
          throw new Error('This should not be requested...');
        }

        return {
          test: 'Dit is een test waarde',
        };
      }}
    >
      <Example translationKey="test" />
    </TranslatorProvider>
  );
};