Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!