question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't get i18next-browser-languageDetector plugin to work

See original GitHub issue

For the past few days I’ve been trying to get this plugin to work: https://github.com/i18next/i18next-browser-languageDetector.

Everything I do fails, and the plugin doesn’t actually do anything. I dug through it’s source code and it uses simple methods to detect the language in the browser, for example by path (http://site.com/LANGUAGE): https://github.com/i18next/i18next-browser-languageDetector/blob/master/src/browserLookups/path.js, by navigator.language: https://github.com/i18next/i18next-browser-languageDetector/blob/master/src/browserLookups/navigator.js and such.

I have confirmed that the plugin actually loads, but simply doesn’t do anything and I got stuck.

To my understanding i18next in astro-i18next gets loaded with page-ssr which from the Astro API page documentation says:

Imported as a separate module in the frontmatter of every Astro page component. Because this stage imports your script, the Astro global is not available and your script will only be run once when the import is first evaluated.

Does this actually mean, that all of the window objects are unavailable for the plugin , and that is why it doesn’t work, or am I missing something?

Configured repo with this plugin is here. From the i18next documentation, changeLanguage gets called on Layout.astro without lng:

Calling changeLanguage without lng uses the language detector to choose the language to set.

This may be not an issue with this plugin, but rather my misunderstading of it or of Astro.

Thanks!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
yassinedoghricommented, Nov 8, 2022

However I would please still like to know, why there’s no debug client side.

Hey @dallyh, have you managed to see the console logs?

I could see them when trying out React. Maybe there needs to be a client-side component for logs to show up? If you still get the problem, could you please create a new issue? I’ll try to tackle it whenever I get the chance.

1reaction
dallyhcommented, Nov 7, 2022

I think that after beta.13 release, it’s safe to say that this can be closed! 🎉

astro-i18next now loads 2 separate i18next configs:

Truly amazing work! But I have to admit I got a little bit lost here. Now astro-i18next should be loaded server side and also client side by default. That basically means that when I’m running the dev server, i should see the debug logs both in browser console and also in the terminal from Vite server (of course having both debug options enabled).

I quickly tried adding this to my config file, but the detection does not seem to work client-side (for example navigating with query string ?lng=cs), and also there are no client side browser console logs. i18nextServer: { debug: true }, i18nextClient: { debug: true, detection: { order: ['querystring', 'navigator', 'path', 'subdomain'], } }

Am I doing something wrong, or I just did not get the concept of this?

Thanks a lot!

EDIT: Allright figured out the first part. When building for SSG then i18next is run and all the strings are translated on runtime. However I would please still like to know, why there’s no debug client side.

Read more comments on GitHub >

github_iconTop Results From Across the Web

language detector used in browser environment for i18next
This is a i18next language detection plugin use to detect user language in the browser with support for: cookie (set cookie i18next=LANGUAGE); sessionStorage...
Read more >
i18next-browser-languageDetector path not working
Solution: i18n.lng property should not be set to when using language detector.
Read more >
i18next-browser-languagedetector Code Examples - Snyk
To help you get started, we've selected a few i18next-browser-languagedetector examples, based on popular ways it is used in public projects. Secure your...
Read more >
Storybook react-i18next addon
This Storybook addon assumes your project is already set up with i18next and ... npm i -S i18next react-i18next i18next-browser-languagedetector ...
Read more >
How to properly internationalize a React application using ...
Overcoming the language barrier for users who use your software is an important topic ... npm install i18next react-i18next i18next-browser-languagedetector.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found