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

strong

v2.0.0

Published

Strong i18n for Express.js-based applications

Downloads

5,218

Readme

Strong i18n

Note: This project is no longer maintained. Please update to another solution.

Internationalization tools for Node.js and Express.

Install It

Add it to your package.json:

npm install strong

Use It

strong.translate() is aliased to t() and i18n() for use in your views.

CoffeeScript:

views/home/index.eco:

<h1><%= @t 'title' %></h1>
OR
<h1><%= @i18n 'title' %></h1>

app.coffee:

@configure ->
  @register '.eco' strong.decorator( zappa.adapter 'eco' )

locales/home/index_en.json:

{
  "title": "My Page Title"
}

Javascript:

views/home/index.ejs:

<h1><%= t('title') %></h1>
OR
<h1><%= i18n('title') %></h1>

app.js:

app.register('.ejs', strong.decorator(require('ejs')));

locales/home/index_en.json:

{
  "title": "My Page Title"
}

Express middleware

The is an optional Express middleware you can use that will parse the Accept-Language header and set a locale property in your Express locals for use in your templates (res.locals.locale). strong.translate (or the t or i18n aliases) will automatically lookup the locale set by the middleware

CoffeeScript:

app.coffee:

app.dynamicHelpers
      locale: strong.localeHelper

Javascript:

app.js:

app.dynamicHelpers({
    locale: strong.localeHelper
});

Stuff You Care About

  • Each view has its own translations file.
  • Translation keys are organized into a hierarchy to match your views.
  • If a translation key isn't found at one level, it backs up the hierarchy looking for it.
  • It's separated into an API and a simple default backend, which you can replace.
  • It "just works" with Zappa when you use Eco and EJS with Express. Other templating libraries may work.
  • Works in CoffeeScript and JavaScript.
  • Supports region-specific locales (pt-PT, pt-BR, en-GB) as well as simple locales (en, es, de)
  • locale can be an array (['pt-BR', 'pt', 'es', 'en-GB', 'en']) and it will look up the best match in order

How To Run the Unit Tests

Build Status

Just use npm:

npm test

Write Your Own Backend

Want to store your translations in Redis, MongoDB, or some other cool new thing? It's easy. The API will handle all the substitutions, and selection among pluralization options.

API-Backend Contract

This is how the API will expect to access the translations.

Replace the storage backend

strong.back = require('strong-redis');

It must respond to navigate calls like this:

# All keys will be of the form '<locale>.<path>.<key>'
strong.back.navigate('en.home.index.title');

When that key corresponds to a message that should be pluralized, return a Map:

{
    'one': '1 message'
  , 'other': '%{count} messages'
}

Otherwise, simply return the string:

'Hello, %{name.first}'

And you're done!