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

ez-i18n

v1.1.5

Published

I18N with built-in pluralize and format funcionality for many languages

Downloads

3

Readme

EZ-I18N

Features:

  • Requires only one external module
  • Contains built-in formatter support (For strings and objects)
  • Plural support for 30 languages!
  • Very fast
  • Translations stored in .yml files

Basic example

  • Create a folder for translations (E.g 'i18n')
  • Create a file with all strings in it, E.g file en.yml
hello: Hello, {who}!
msgCount: You have {count} %message&{count}%

plurals:
    message:
        - message
        - messages
  • Then init module in your app:
const ez_i18n = require('ez-i18n');
const translator = new ez_i18n({
    langDir:__dirname+'/i18n/'
});
/**
 * Syntax for that command is 
 *   ez_i18n(<options>);
 * Options object contain these keys:
 * langDir <STRING> - directory, where translations are stored
 * encoding <STRING> - encoding for translation files (Optional, defaults to UTF-8)
 * warns <BOOL> - show a warnings for missing translations? (Optional, defaults to false)
 * debug <BOOL> - show a debug info. Dont use it. (Optional, defaults to false)
 * returns <FUNCTION>
 **/
  • Create a translator for a specified language:
const _ = translator('en');
/**
 * Syntax for that command is 
 * translator(<lang>)
 * lang <STRING> - language to use, e.g 'en'
 * returns <FUNCTION>
 **/
  • And use it:
console.log(_('hello', {who: 'world'}));
// Hello, world!
console.log(_('msgCount', {count: 1}));
// You have 1 message
console.log(_('msgCount', {count: 2}));
// You have 2 messages

##Format string

Syntax is %{string} or %{num}
If num used, then function uses params passed to function:
  E.g: _('str','test1','test2','test3')
    %{1} will be 'test1'
    %{2} will be 'test2'
    %{3} will be 'test3'

Othervise strings from object will be used:
  E.g: _('str',{test1:'test2',test3:'test4',test5:'test6'})
    %{test1} will be 'test2'
    %{test3} will be 'test4'
    %{test5} will be 'test6'

##Plurals

Syntax is #{string,count}

##Randoms

Syntax is ${string}

##Test results

  Basic
    #Init
      ✓ should start correctly
      ✓ should return translator function
    #Translate
      ✓ should return correct string for every language
    #Templating
      ✓ should return correct templated string for all arguments
      ✓ should return correct templated string for data object
    #Pluralizing
      ✓ should correctly pluralize a string for all languages
    #Misc
      ✓ can work for yml structures


  7 passing (8ms)