How to use the i18next-express-middleware.handle function in i18next-express-middleware

To help you get started, we’ve selected a few i18next-express-middleware examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zeit / next.js / examples / with-react-i18next / server.js View on Github external
.then(() => {
        const server = express()

        // enable middleware for i18next
        server.use(i18nextMiddleware.handle(i18n))

        // serve locales for client
        server.use('/locales', express.static(path.join(__dirname, '/locales')))

        // missing keys
        server.post('/locales/add/:lng/:ns', i18nextMiddleware.missingKeyHandler(i18n))

        // use next.js
        server.get('*', (req, res) => handle(req, res))

        server.listen(3000, (err) => {
          if (err) throw err
          console.log('> Ready on http://localhost:3000')
        })
      })
  })
github i18next / react-i18next / example / nextjs / server.js View on Github external
.then(() => {
        const server = express()

        // enable middleware for i18next
        server.use(i18nextMiddleware.handle(i18n));

        // serve locales for client
        server.use('/locales', express.static(__dirname + '/locales'))

        // missing keys
        server.post('/locales/add/:lng/:ns', i18nextMiddleware.missingKeyHandler(i18n));

        // use next.js
        server.get('*', (req, res) => handle(req, res))

        server.listen(3000, (err) => {
          if (err) throw err
          console.log('> Ready on http://localhost:3000')
        })
      })
github camelaissani / loca / server.js View on Github external
app.use(bodyParser.urlencoded({
    extended: true
}));
app.use(bodyParser.json());
app.use(methodOverride());
app.use(session({
    secret: 'loca-secret',
    rolling: true,
    cookie: {
        //      min  s     ms
        maxAge: 10 * 60 * 1000 // 10 minutes
    }
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(i18nMiddleware.handle(i18next));
app.use(function(req, res, next) {
    app.locals.Intl = {
        NumberFormat: new Intl.NumberFormat(req.language, { style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2 }),
        NumberFormatPercent: new Intl.NumberFormat(req.language, { style: 'percent', minimumFractionDigits: 2, maximumFractionDigits: 2 }),
        NumberFormatCurrency: new Intl.NumberFormat(req.language, { style: 'currency', currency: req.t('__currency_code') })
    };
    const splitedLanguage = req.language.split('-');
    moment.locale(splitedLanguage[0]);
    next();
});
// Icon / static files
app.use(favicon(path.join(dist_directory, 'images', 'favicon.png'), {
    maxAge: 2592000000
}));
app.use('/node_modules', express.static(path.join(__dirname, '/node_modules')));
app.use('/public', express.static(dist_directory));
github mercari / mtc2018-web / web / server.js View on Github external
.then(() => {
        const server = express()

        // mercari tech conf 2017
        server.use('/2017', express.static(path.join(__dirname+'/static/2017')));

        // enable middleware for i18next
        server.use(i18nextMiddleware.handle(i18n))

        // serve locales for client
        server.use('/locales', express.static(path.join(__dirname, '/locales')))

        // missing keys
        server.post('/locales/add/:lng/:ns', i18nextMiddleware.missingKeyHandler(i18n))

        // redirect root access to /2018
        // server.get('/', (req, res) => res.redirect('/2018'))

        // use next.js
        // server.get('*', (req, res) => handle(req, res))
        server.use(handler)

        server.listen(8080, (err) => {
          if (err) {
github Alheimsins / bigfive-web / server.js View on Github external
app.prepare().then(() => {
        const server = express()
        const db = mongo(config.DB_CONNECTION)
        const collection = db.collection(config.DB_COLLECTION)

        server.use(helmet())
        server.use(express.json())
        server.use(i18nextMiddleware.handle(i18n)) // Enable middleware for i18next
        server.use('/locales', express.static(join(__dirname, '/locales'))) // Serve locales for client
        server.use(requestCountry.middleware({
          privateIpCountry: 'en'
        }))

        server.get('/sitemap.xml', (req, res) => {
          const filePath = join(__dirname, 'static', 'sitemap.xml')
          return app.serveStatic(req, res, filePath)
        })

        server.get('/service-worker.js', (req, res) => {
          const filePath = join(__dirname, '.next', 'service-worker.js')
          return app.serveStatic(req, res, filePath)
        })

        server.get('/api/login', (req, res) => {
github weseek / growi / src / server / crowi / express-init.js View on Github external
app.use(flash());

  app.use(middleware.swigFilters(crowi, app, swig));
  app.use(middleware.swigFunctions(crowi, app));

  app.use(middleware.csrfKeyGenerator(crowi, app));

  // switch loginChecker
  if (Config.isEnabledPassport(config)) {
    app.use(middleware.loginCheckerForPassport(crowi, app));
  }
  else {
    app.use(middleware.loginChecker(crowi, app));
  }

  app.use(i18nMiddleware.handle(i18next));
};
github weseek / growi / src / server / crowi / express-init.js View on Github external
app.use(flash());

  app.use(middleware.swigFilters(crowi, app, swig));
  app.use(middleware.swigFunctions(crowi, app));

  app.use(middleware.csrfKeyGenerator(crowi, app));

  // switch loginChecker
  if (Config.isEnabledPassport(config)) {
    app.use(middleware.loginCheckerForPassport(crowi, app));
  }
  else {
    app.use(middleware.loginChecker(crowi, app));
  }

  app.use(i18nMiddleware.handle(i18next));

  // add custom functions to express res
  express.response.apiv3 = function(obj) { // not arrow function
    // obj must be object
    if (typeof obj !== 'object' || obj instanceof Array) {
      throw new Error('invalid value supplied to res.apiv3');
    }

    this.json({ data: obj });
  };

  express.response.apiv3Err = function(_err, status = 400) { // not arrow function
    if (!Number.isInteger(status)) {
      throw new Error('invalid status supplied to res.apiv3Err');
    }
github eden-js / cli / lib / bundles / locale / controllers / locale.js View on Github external
build () {
    // Run this
    this.eden.pre('view.render', this._create);
    this.eden.post('view.render', this._remove);

    // Hooks
    this.eden.pre('socket.call.opts',     this._socket);
    this.eden.pre('socket.endpoint.opts', this._socket);

    // Use middleware
    this.eden.router.use(middleware.handle(locale.locale));

    // Add middleware
    this.eden.router.use(this._middleware);

    // Use get
    this.eden.router.get('/locales/:ns.:lng.json', (req, res) => {
      // Run try/catch
      try {
        // Require locales
        res.json(require(global.appRoot + '/cache/locales/' + req.params.ns + '.' + req.params.lng + '.json'));
      } catch (e) {
        // Return nothing
        res.json({});
      }
    });
  }
github studiometa / react-next-starter / server / server.js View on Github external
? prepareUrls(this.protocol, this.host, port).localUrlForBrowser
      : null;

    // Enable cors on production
    this._enableCORS();

    // Initialize fake-API
    this._initFakeApi();

    // Listen to the public folder
    this.server.use('/', express.static(paths.appPublic));

    if (this.config.lang.enabled) {

      // enable middleware for i18next
      this.server.use(i18nextMiddleware.handle(i18nInstance));

      // serve locales for client
      this.server.use('/locales', express.static(this.config.lang.localesPath));
    }


    // Here we are adding new server listeners for the custom routes of the application. We are making this
    // differently depending on if the route translation has been enable or not
    this._initMainListeners();

    // Fallback server entry for requests that do not match any defined route
    this._initFallbackListener();

    try {
      this.nextApp.server = await this.server.listen(port);
github magma / magma / symphony / app / fbcnms-packages / fbcnms-i18n / index.js View on Github external
export function getLocaleHandler(i18NextInstance: any) {
  return [
    i18nextMiddleware.handle(i18NextInstance),
    (req: any, res: any) => {
      // this comes from language detection
      const locale = req.i18n.language;
      let ns = req.params[req.i18n.options.detection.nsLookupPath || 'ns'];
      if (!ns) {
        ns = 'translation';
      }
      const getIsLangLoaded = () => req.i18n.hasResourceBundle(locale, ns);
      return new Promise((resolve, reject) => {
        if (getIsLangLoaded()) {
          resolve(req.i18n.getResourceBundle(locale, ns));
        } else {
          req.i18n.loadLanguages(locale, err => {
            const isLangLoaded = getIsLangLoaded();
            if (err || !isLangLoaded) {
              return reject(err);

i18next-express-middleware

express middleware for i18next

MIT
Latest version published 5 years ago

Package Health Score

51 / 100
Full package analysis

Popular i18next-express-middleware functions