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

express-t

v1.1.0

Published

I18n for Express apps.

Downloads

2

Readme

express-t

Helper method for translations. It has one concern; look up translations inside JSON-formatted locale files. By default it'll lookup files that match ./config/locales/*.json. For keys it uses a dotted-notation such that 'model.posts.name' will reference the value for a key name which is a member of object posts which is a member of object model.

./config/locales/en.json
{
  "en": {
    "model": {
      "posts": {
        "name": "Posts"
      }
    }
  }
}

Getting started

First add express-t to your dependencies. Then assign the helper function to an app local that'll be used within your views. Be sure to pass in the base path of your project.

$ npm install express-t --save
./config/app.js
const express_t = require('express-t')
const base = path.join(__dirname, '..')
app.locals.t = express_t(base)
./app/views/posts/index.html.ejs
<h3>Model: <%- t(locale, 'model.posts.name') %></h3>
<!-- en, 'Model: Posts' -->
<!-- es, 'Model: Publicaciones' -->
<!-- fr, 'Model: Postes' -->

Adding locales

To add language support just place translations into a JSON file named using the ISO 639-1 standard of two-letter language codes.

ls -la ./config/locales
#=> ./config/locales/en.json
#=> ./config/locales/es.json
#=> ./config/locales/fr.json
#=> ...

Place configuration inside your locale.js initializer file.

cat ./config/initializers/locale.js
#=> module.exports = {
#=>   available_locales: ['de', 'en', 'es', 'fr', 'it', 'ja', 'pt'],
#=>   default_locale: 'en',
#=> }

Reference translations inside your views using dotted notation.

cat ./app/views/welcome/hello.html.ejs
#=> <h1><%- t(locale, 'welcome.greeting') %></h1>
cat ./config/locales/en.json
#=>{
#=>  "en": {
#=>    "welcome": {
#=>      "greeting": "Hello, friend!",
#=>      ...

Changelog

Get the project's history in CHANGELOG.md.

Maintainer

Andy Bettisworth [email protected] https://andybettisworth.com

License

This project is released under the MIT License.