Skip to content

Instantly share code, notes, and snippets.

@mashpie
Last active June 19, 2023 07:47

Revisions

  1. mashpie revised this gist Apr 28, 2013. 1 changed file with 0 additions and 10 deletions.
    10 changes: 0 additions & 10 deletions i18n-express-cookie-app.js
    Original file line number Diff line number Diff line change
    @@ -21,16 +21,6 @@ app.configure(function () {
    // i18n init parses req for language headers, cookies, etc.
    app.use(i18n.init);

    // binding template helpers to request (Credits to https://github.com/enyo #12)
    app.use(function (req, res, next) {
    res.locals.__ = res.__ = function () {
    return i18n.__.apply(req, arguments);
    };
    res.locals.__n = res.__n = function () {
    return i18n.__n.apply(req, arguments);
    };
    next();
    });
    });

    // serving homepage
  2. mashpie revised this gist Mar 18, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion i18n-express-cookie-app.js
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ i18n.configure({
    // setup some locales - other locales default to en silently
    locales: ['en', 'ru', 'de'],

    // sets a custom cookie name to parse locale settings from
    // sets a custom cookie name to parse locale settings from
    cookie: 'yourcookiename',

    // where to store json files - defaults to './locales'
  3. mashpie revised this gist Mar 18, 2013. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions i18n-express-cookie-app.js
    Original file line number Diff line number Diff line change
    @@ -7,10 +7,7 @@ i18n.configure({
    // setup some locales - other locales default to en silently
    locales: ['en', 'ru', 'de'],

    // you may alter a site wide default locale
    defaultLocale: 'en',

    // sets a custom cookie name to parse locale settings from
    // sets a custom cookie name to parse locale settings from
    cookie: 'yourcookiename',

    // where to store json files - defaults to './locales'
  4. mashpie revised this gist Mar 18, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion i18n-express-cookie-app.js
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ i18n.configure({
    cookie: 'yourcookiename',

    // where to store json files - defaults to './locales'
    directory: './configs/locale'
    directory: __dirname + '/locales'
    });

    app.configure(function () {
  5. mashpie revised this gist Mar 18, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion package.json
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    {
    "name": "express-example",
    "name": "i18n-express-cookie-example",
    "version": "0.0.0",
    "author": "Marcus Spiegel <marcus.spiegel@gmail.com>",
    "dependencies": {
  6. mashpie revised this gist Mar 18, 2013. 1 changed file with 1 addition and 10 deletions.
    11 changes: 1 addition & 10 deletions i18n-express-cookie-app.js
    Original file line number Diff line number Diff line change
    @@ -14,19 +14,10 @@ i18n.configure({
    cookie: 'yourcookiename',

    // where to store json files - defaults to './locales'
    directory: './configs/locale',

    // enabled some debug output - defaults to false
    debug: true
    directory: './configs/locale'
    });

    app.configure(function () {
    // nice favicon
    app.use(express.favicon());

    // nicer logging
    app.use(express.logger('dev'));

    // you will need to use cookieParser to expose cookies to req.cookies
    app.use(express.cookieParser());

  7. mashpie renamed this gist Mar 9, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. mashpie created this gist Mar 9, 2013.
    56 changes: 56 additions & 0 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    // usual requirements
    var express = require('express'),
    i18n = require('i18n'),
    app = module.exports = express();

    i18n.configure({
    // setup some locales - other locales default to en silently
    locales: ['en', 'ru', 'de'],

    // you may alter a site wide default locale
    defaultLocale: 'en',

    // sets a custom cookie name to parse locale settings from
    cookie: 'yourcookiename',

    // where to store json files - defaults to './locales'
    directory: './configs/locale',

    // enabled some debug output - defaults to false
    debug: true
    });

    app.configure(function () {
    // nice favicon
    app.use(express.favicon());

    // nicer logging
    app.use(express.logger('dev'));

    // you will need to use cookieParser to expose cookies to req.cookies
    app.use(express.cookieParser());

    // i18n init parses req for language headers, cookies, etc.
    app.use(i18n.init);

    // binding template helpers to request (Credits to https://github.com/enyo #12)
    app.use(function (req, res, next) {
    res.locals.__ = res.__ = function () {
    return i18n.__.apply(req, arguments);
    };
    res.locals.__n = res.__n = function () {
    return i18n.__n.apply(req, arguments);
    };
    next();
    });
    });

    // serving homepage
    app.get('/', function (req, res) {
    res.send(res.__('Hello World'));
    });

    // starting server
    if (!module.parent) {
    app.listen(3000);
    }
    9 changes: 9 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    {
    "name": "express-example",
    "version": "0.0.0",
    "author": "Marcus Spiegel <marcus.spiegel@gmail.com>",
    "dependencies": {
    "express": "*",
    "i18n": "*"
    }
    }