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

translations

v2.2.1

Published

translations api for node.js, browsers and the command line

Downloads

1,621

Readme

translations version build

translations api for node.js, browsers and the command line.

Installation

npm install translations

Usage

var locale = require('locales/de-DE.json'); // node.js;
var locale = window.locale; // browser example

var t = translations(locale); // production mode: ignores most errors
var t = translations(locale, true); // development mode: throws more errors

t('How are you?');
// "Wie geht es dir?"

t('Hello {name}, how are you?', { name: 'Max' });
// "Hallo Max, wie geht es dir?"

t('Hello {name}, how is {thing}?', { name: 'Max', thing: t('the weather') });
// "Hallo Max, wie ist das Wetter?"

t('undefined key in locale');
// throws error in development mode for undefined keys
// returns empty string in production mode

t('Hello {name}, how is {thing}?', { name: 'Max' });
// throws error in development mode for undefined variables
// prints placeholders in production mode

de-DE.json

{
  "How are you?": "Wie geht es dir?",
  "Hello {name}, how are you?": "Hallo {name}, wie geht es dir?",
  "Hello {name}, how is {thing}?": "Hallo {name}, wie ist {thing}?",
  "the weather": "das Wetter"
}

Command Line

Installation

npm install translations -g # if you want to use the cli globally

sync

# sync locales
translations sync <master> <target>

# example
translations sync locales/en.json locales/de-DE.json

translations sync syncs the master translations file with the target one:

If target has values that are not strings, it throws an error.

If target does not exist yet, a copy of master will be created with the target’s name (de-DE.json).

If target does already exist, the command does the following:

  • every key not found in master is removed
  • every key not found in target is added

export

# export locales for browser usage
translations export <inputDirectory> <outputDirectory> --assign <variable>

translations export will create or overwrite the given output directory with js files for valid locales in the input directory. Each js file assigns the locale’s translations to the given variable (or window.locale by default).

LICENSE

MIT (2015) Maximilian Hoffmann