I18n for Express apps.

Usage no npm install needed!

<script type="module">
  import expressT from '';



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 '' will reference the value for a key name which is a member of object posts which is a member of object model.

  "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
const express_t = require('express-t')
const base = path.join(__dirname, '..')
app.locals.t = express_t(base)
<h3>Model: <%- t(locale, '') %></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!",
#=>      ...


Get the project's history in


Andy Bettisworth


This project is released under the MIT License.