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.

Allow for alternative language detection

See original GitHub issue

What problem does this feature solve?

Currently, Nuxt-i18n has an option to allow for browser detection which is great but not always accurate. It would be nice to allow for an alternative source to detect users language preference.

What does the proposed changes look like?

I’m proposing an option to allow for an alternative provider to detect a users language needs. For example, a geolocation service that provides an API that returns geodata.

In this particular instance my app is in SPA mode.

nuxt.config.js:

detectBrowserLanguage: {
            api: "https://someAPI.com/location", // Just as an example of how this can be checked
            useCookie: true,
            cookieKey: 'i18n_redirected'
        },

middleware.js:

if (detectBrowserLanguage) {
let browserLocale

    if (useCookie && (browserLocale = getCookie()) && browserLocale !== 1 && browserLocale !== '1') {
    } else if (isSpa && apiOption) {
        browserLocale = store.state.geoData.country.toLowerCase();

Something like that. I’ve made these edits to middleware.js and it’s working for me. But I’m also seeing that an entry is made to the history then I’m redirected to the proper prefixed page.

What I would expect to happen for example if someone comes to ‘/’ that only one entry is made to the history. There needs to be some type of check if route is the same then no entry is made. Maybe this is something that needs to happen as a plugin?

<div align="right">This feature request is available on Nuxt community (#c196)</div>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
rchlcommented, Jul 1, 2019

I’d say it would be too heavy to do it for every page load request but when used with conjunction with cookie storage, it would be OK and useful. Maybe let’s reopen this?

2reactions
LevGlushchenkocommented, Jul 2, 2019

Yeap, it woul’d be nice

Read more comments on GitHub >

github_iconTop Results From Across the Web

Turn on automatic language detection - Microsoft Support
The Detect language automatically option, available in Word and Outlook on Windows, detects the language that you are typing and automatically enables the ......
Read more >
Allow for alternative language detection · Issue #207 - GitHub
I'm proposing an option to allow for an alternative provider to detect a users language needs. For example, a geolocation service that ...
Read more >
4 Python libraries to detect English and Non-English language
We will discuss spacy-langdetect, Pycld2, TextBlob, and Googletrans for language detection. This solve natural language processing (NLP) ...
Read more >
Enable language recognition in Speech-to-Text API
This feature is ideal for apps that need to transcribe short statements like voice commands or search. You can list up to three...
Read more >
How to handle language detection and suggestion?
There is an Accept-language HTTP field sent to your web server with every user request. This field is controlled by the browser, and...
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