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

dictionary-react

v1.1.0

Published

Dictionary is a JS library that helps automate language switching. This library can greatly speed up the development of language versions for any type of application. This library is new and requires a lot of improvements, but you can already try it out.

Downloads

1,439

Readme

Dictionary

Dictionary is a JS library that helps automate language switching.

This library can greatly speed up the development of language versions for any type of application. This library is new and requires a lot of improvements, but you can already try it out. Initially, it was supposed to use Dictionary with React.

Installation

To install, use:

  npm install dictionary

How to use

First, we create JSON files where all data that is subject to language change will be stored.

//For English lang
{
    "title": "Dictionary"
}

//And for Deutschland lang
{
    "title": "Wörterbuch"
}

If the text should contain some dynamic parameter, add <d.*someVariable*> to this place, where someVariable is an identifier that is used to replace this section with the parameter being passed.

// You can type any param name "param" or "num" or "sometrash". Wherever you want.
{
    "text": "Text for <d.param> exemple"
}

There may be several such parameters.

{
    "text": "Text <d.num> for <d.param> exemple <d.param>"
}

Then we create an index file and create a dictionary.

const initialState = {
    en: english,
    de: deutschland
}

export const dictionaryLangs = createDictionary(initialState)

To access the dictionary at the top level of the application, we need to connect our dictionary.

import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

import { Dictionary } from "./Dictionary";
import { dictionaryLangs } from "./dictionary/dictionaryLangs";

const root = ReactDOM.createRoot(
    document.getElementById('main') as HTMLElement
);

root.render(
    <Dictionary languages={dictionaryLangs}>
        <App />
    </Dictionary>
);

After that, to get data from the dictionary, we call the useDictionary() function.

// {} in the second parameter is required
const title = useDictionary(state => state.title, {}),

Here I should say that the dictionary selects the first language you added as the main one.

If the text contains a parameter that needs to be replaced, we pass it as the second argument.

// Here we should use only those parameters that we have noted in the text.
const text = useDictionary(state => state.text, {param: "some param", num: 2}),

To change the language, you need to initialize the useLangChanger() function and then pass the name of the language you added earlier as an argument.

const changeLang = useLangChanger()

const handleClick = () => {
    changeLang("de")
}

Congratulations, you are amazing.

Features

  • Code optimization
  • Possibility to obtain processed data for the entire section at once

Authors

License

MIT