Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda