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

micro-i18n

v1.0.1

Published

basic js micro library for i18n, with support for placeholders and multiple plural forms

Downloads

2

Readme

micro-i18n npm Build Status

Basic js micro library for i18n, with support for placeholders and multiple plural forms.

~1.8kb

Installation

$ npm install micro-i18n

Usage

Just import it:

import i18n from 'micro-i18n'

If you are using it directly in the browser, you can access it with the i18n global.

Api

We have just two static methods: i18n.setLan(lang : Object) and i18n.t(key : string, placeholders? : Object)

const enUS = {
  EASY: 'easy',
  HATE_SOMETHING: 'I hate {{something}}!',
  REALLY_HATE_SOMETHING: 'I hate {{something}}! I really hate {{something}}!',
  HATE_SOMETHING_LIKE_THING: 'I hate {{something}}! But I like {{thing}}!',
  QUANTITY: {
    0: 'no {{what}}',
    1: '1 {{what}}',
    n: '{{n}} {{what}}'
  },
  MESSAGES: {
    0: 'messages',
    1: 'message',
    n: 'messages'
  } 
}

const ptBR = {
  EASY: 'fácil',
  HATE_SOMETHING: 'Eu odeio {{something}}!',
  REALLY_HATE_SOMETHING: 'Eu odeio {{something}}! Eu realmente odeio {{something}}!',
  HATE_SOMETHING_LIKE_THING: 'Eu odeio {{something}}! Mas eu gosto de {{thing}}!',
  QUANTITY: {
    0: 'nenhum {{what}}',
    1: '1 {{what}}',
    n: '{{n}} {{what}}'
  },
  MESSAGES: {
    0: 'mensagens',
    1: 'mensagem',
    n: 'mensagens'
  } 
}

i18n.setLang(enUS)
i18n.t('EASY') //easy

Placeholders

i18n.t('HATE_SOMETHING', {something: 'haters'}) //I hate haters!
i18n.t('REALLY_HATE_SOMETHING', {something: 'haters'}) //I hate haters! I really hate haters!
i18n.t('HATE_SOMETHING_LIKE_THING', {something: 'haters', thing: 'pizza'}) //I hate haters! But I like pizza!

Plural

i18n.t('MESSAGES', {n: 0}) //messages
i18n.t('MESSAGES', {n: 1}) //message
i18n.t('MESSAGES', {n: 10}) //messages

Placeholders + plural

i18n.t('QUANTITY', {n: 0, what: 'ducks'}) //no ducks
i18n.t('QUANTITY', {n: 1, what: 'duck'}) //1 duck
i18n.t('QUANTITY', {n: 10, what: 'ducks'}) //10 ducks
i18n.t('QUANTITY', {n: 10, what: i18n.t('MESSAGES', {n: 10})}) //10 messages

Setting the lang

i18n.setLang(enUS)
i18n.t('EASY') //easy
i18n.setLang(ptBR)
i18n.t('EASY') //fácil

Fallback

If a key is undefined it will be returned as fallback