i18next / i18next-express-middleware

[deprecated] can be replaced with i18next-http-middleware
https://github.com/i18next/i18next-http-middleware
MIT License
206 stars 52 forks source link

How to get locale from second parametr in path ? #205

Closed golubvladimir closed 4 years ago

golubvladimir commented 4 years ago

My config

i18next
  .use(i18nextMiddleware.LanguageDetector)
  .use(FilesystemBackend)
  .init({
    fallbackLng: ['en'],
    preload: ["en", "ru"],
    detection: {
      order: ['path'],
      lookupPath: 'lng',
      caches: false
    },
    backend: {
      loadPath: path.join(__dirname, '../lang/json/{{lng}}.json'),
      jsonIndent: 2,
    }
  });

app.use(
  i18nextMiddleware.handle(i18next, {
    removeLngFromUrl: false
  })
);

app.get('/api/:lng/test-lang', (req, res) => {
  console.log(req.t('test'));
});

GET http://localhost:3001/api/ru/test-lang GET http://localhost:3001/api/en/test-lang I get english translate.

Test
Test

Why is i18next: languageChanged equal api ?

golubvladimir commented 4 years ago

Fix config

    detection: {
      order: ['path'],
      lookupPath: 'api/lng',
      lookupFromPathIndex: 1,
      caches: false
    },