🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

i18n-express-subdirs

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

i18n-express-subdirs

Middleware for express that adds the language to the url.

unpublished
latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

i18n-express-subdirs

A middeware for express that makes your app ready for internationalisation using Subdirectories with gTLDs. It redirects /someurl to /en/someurl, /de/someurl, ... using 'accept-language' header to guess language settings and sets the locale in the module i18n. This URL structure is one of the ways to make your site multilingual for more information read at the Search Console Help Center

Install

npm install i18n-express-subdirs --save

Usage

Minimal example

var express = require('express');
var app = express();
var i18nSubdirs = require('i18n-express-subdirs');

app.use(i18nSubdirs({
  //for all the options take a look at the i18n module
  locales: ['en', 'de'],
  defaultLocale: 'en',
  directory: __dirname + '/locales'
}));

app.get('/*', function (req, res) {
  res.send(res.__('Hello World!'));
  //for all methods __, __n, ... take a look at the i18n module
});

app.listen(3000, function () {
  console.log('Example app listening on port 3000!')
})

If you already use i18n at a different place in your app you can reuse the i18n object and don't need to reconfigure it again

//var app; ...
var i18n = require('i18n');
var i18nSubdirs = require('i18n-express-subdirs');

i18n.configure({
  locales: ['en', 'de'],
  defaultLocale: 'en',
  directory: __dirname + '/locales'
});

app.use(i18nSubdirs(i18n));

//app.use('/', routes);
//app.listen(address);
//...

To tell google of your different languages you could use hreflang (read more about that at the Search Console Help Center).

app.get('/*', function (req, res) {
  //...
  res.write('<link rel="alternate" href="' + req.url + '" hreflang="x-default" />');
  res.getLocales().forEach(function (lang) {
    res.write('<link rel="alternate" href="/' + lang + req.url + '" hreflang="' + lang + '" />');
  });
  //...
  res.end();
});

FAQs

Package last updated on 10 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts