Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

246
Vistas
How to append a query text in URL in Node Express?

I'm using i18next for the internationalization. For a default language, I have set up to detect the language from the URL query or from the accept-language header. (there are two languages, "?lng=en" and "?lng=zh-hant") Now I'm wondering how to append either of the two language queries to the default URL http://example.com/ so that it becomes http://example.com/?lng=en, after detecting the language from the accept-language header. I want the language query present in the URL always, and I want it to be set as the preferred language from accept-language header.

I've tried to parse the accept-language and then redirect using app.use() in Express, but I was unsuccessful. I couldn't find something relevant to my situation and I'm quite new to Javascript.

In short, I want to append "lng" variable from loadPath() to the URL as a query.

const i18next = require('i18next');
const Backend = require('i18next-fs-backend');
const middleware = require('i18next-http-middleware');
i18next.use(Backend)
    .use(middleware.LanguageDetector)
    .init({
        detection: detection_options,
        fallbackLng: 'en',
        backend: {
            loadPath(lng, ns) {
                if (lng === 'zh' || lng === 'zh-HK' || lng === 'zh-TW') {
                    return path.join(__dirname, 'locales/zh-hant.json');
                } else if (lng === 'en-US') {
                    return path.join(__dirname, 'locales/en.json');
                }
                return path.join(__dirname, 'locales/{{lng}}.json');
            }
        }
    })
app.use(middleware.handle(i18next));
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda