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

trslate

v1.6.4

Published

Translate function

Readme

trslate

This package exports a TContext class The TContext class exports three main functions, the first one is used to translate, the second one is used to check if a language is valid and the third one is a shortcut to not specify the language every time in the first one. There is also another function which allows you to toggle strict mode

Example

import { TContext } from 'trslate';
const schema = [];
const translate = new TContext(schema, ...);

this is a code to demostrate how it works, the class accept a minimum of one param, every other param you pass is the corresponding translation object for every language in the schema. Obviously if you pass a new param, you will need to add a new string element in the array


setStrict function: This function allows you to toggle strict mode

Example

let m = true;
const lang = 'invalid';
const key = 'invalid';
translate.setStrict(m);
translate.t(lang, key); // gives error
m = false;
translate.setStrict(m);
translate.t(lang, key); // doesn't give error

t function: is the actual function used to translate

Example

const lang = '';
const key = '';
console.log(translate.t(lang, key));

this function accept two paramethers, the first one is the language you want to translate into and the second one is the object key from which to take the string that will be translated


isValidLang function: used to check if a language is valid

Example

const lang = '';
if (translate.isValidLang(lang)) {
    // now typescript knows that lang can only be an element of the schema array
}

this function accept one paramether, the language and it checks if the translation in that language was provided, it returns a boolean


useLang function: a shortcut that returns a function to not specify the language every time

Example

const lang = '';
const t = translate.useLang(lang);
const key = '';
console.log(t(key));

this function accept one paramether, the language you want to translate into, and it returns a function that allows you to not specify the language everytime but only the key


it has also a setLang function attached which allows you to change the language without creating another function

Example

let lang = '';
const t = translate.useLang(lang);
lang = 'en';
t.setLang(lang);
const key = '';
console.log(t(key));