Giter VIP home page Giter VIP logo

Comments (6)

jamuhl avatar jamuhl commented on June 8, 2024

is it needed? the detection can result in en-US where i18next will use en if set load to languageOnly

from i18next-browser-languagedetector.

balciseri avatar balciseri commented on June 8, 2024

I'm not getting what i'm expecting without this fix.
Example:

var options = { debug: true, fallbackLng: "en", load: 'languageOnly', backend: { loadPath: './locales/{{lng}}/{{ns}}.json', addPath: './locales/add/{{lng}}/{{ns}}', allowMultiLoading: false, crossDomain: false, }, detection: { order: ['localStorage', 'cookie', 'navigator'], lookupLocalStorage: 'i18nextLng', lookupCookie: 'i18next', caches: ['localStorage', 'cookie'], cookieMinutes: 60 * 60 * 24 * 365, } };

I get : i18next: languageChanged it-IT instead of i18next: languageChanged it
http://puu.sh/o70T6/1986bec560.png

Also i18next.language returns "it-IT" instead of "it"

from i18next-browser-languagedetector.

jamuhl avatar jamuhl commented on June 8, 2024

yes...language is changed to it-IT does not mean it will load and use it-IT. Internal 18next will always generate an array of language(+region) to lookup: https://github.com/i18next/i18next/blob/master/src/LanguageUtils.js#L58

en-US (without load option) ==> ['en-US', 'en', 'fallbackLng']
en-US (with load option language only) ==> ['en', 'fallbackLng']

i18next.languages should return what you expect. (https://github.com/i18next/i18next/blob/master/src/i18next.js#L193)

from i18next-browser-languagedetector.

balciseri avatar balciseri commented on June 8, 2024

To be clear: with load: 'languageOnly' should i get "it-IT" or "it" when performing i18next.language ?
http://puu.sh/o71uy/13a0796b7e.png
Right now i'm getting "it-IT".

Reading the code you linked seems that "it-IT" it's the correct answer to i18next.language.
I was expecting it to be "it" with the languageOnly option.
I will have to change my app's code because it is based on the wrong assumption. Thank you!

from i18next-browser-languagedetector.

balciseri avatar balciseri commented on June 8, 2024

Edit: i didn't see the "s" in your answer.
i18next.languages is indeed what i am looking for.
Thanks again.

Edit2: i can confirm that i18next.languages[0] is returning the "it" i was expecting.
I was not sure this was the right path.
Because the first time you load the app in the localstorage the "it-It" value will be stored but if for example the user changes the language of the website then the value in the localStorage wil lbe just "it" because in the code i have for example: i18next.changeLanguage("it").
This is not a problem at all because with 18next.languages[0] works in both cases.

from i18next-browser-languagedetector.

jamuhl avatar jamuhl commented on June 8, 2024

closing...if you got any other issue/question feel free to ask.

from i18next-browser-languagedetector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.