i18next/i18next-browser-languageDetector

lng does not work if is after a #

totszwai opened this issue ยท 2 comments

๐Ÿ› Bug Report

The following URLs does not work:

http://localhost:8080/#/something?lng=fr
http://localhost:8080/#/something/?lng=fr

Only works if the query string is before a #.

http://localhost:8080/?lng=fr#/something

To Reproduce

  const languageDetector = new LanguageDetector(null, {
    // order and from where user language should be detected
    order: ['querystring', 'cookie', 'localStorage', 'sessionStorage', 'navigator', 'htmlTag', 'path', 'subdomain'],

    // keys or params to lookup language from
    lookupQuerystring: 'lng',
    lookupCookie: 'i18next',
    lookupLocalStorage: 'i18nextLng',
    lookupSessionStorage: 'i18nextLng',
    lookupFromPathIndex: 0,
    lookupFromSubdomainIndex: 0,

    // cache user language on
    caches: ['localStorage', 'cookie'],
    excludeCacheFor: ['cimode'], // languages to not persist (cookie, localStorage)

    // optional htmlTag with lang attribute, the default is:
    htmlTag: document.documentElement,

    // optional set cookie options, reference:[MDN Set-Cookie docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie)
    cookieOptions: { path: '/', sameSite: 'strict' }
  });

  if (!i18n.isInitialized) {
    i18n
      .use(languageDetector)

Expected behavior

Expect the lng in the querystring to work regardless of position

Your Environment

node v14
i18next-browser-language 6.1.2

adrai commented

In theory this is not part of the querystring, because of the # fragment delimiter....
but I just provided a fallback with v6.1.4... can you try?

@adrai Confirmed that it work, thanks a lot for providing a fallback and publishing it so quickly! ๐Ÿ‘