Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add browser language detector to automatically switch to default browser lang #2022

Merged
merged 18 commits into from
Aug 7, 2023

Conversation

anshgoyalevil
Copy link
Member

Description

  • This PR leverages the browser API to detect the user's default language selected in order of an array. For example, the user has selected German, English, Chinese, etc in their browser's settings.
  • The website would check that array of languages, like here, it would get ['de', 'en', ..]
  • It would then check if the first language of this array is having translation available, if yes, then it would change the language on the first render, and this continues till it finds one. In case no lang is available, it would default to 'en'.
  • If the user picks language from the language picker, it would override this behavior and the future sessions would use the language selected manually by the user.

Related issue(s)

#2021

@netlify
Copy link

netlify bot commented Aug 2, 2023

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 962ad49
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/64d09d38e34a0b00083c8e36
😎 Deploy Preview https://deploy-preview-2022--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@anshgoyalevil anshgoyalevil changed the title Browser Add browser language detector to automatically switch to default browser lang Aug 2, 2023
@anshgoyalevil anshgoyalevil changed the title Add browser language detector to automatically switch to default browser lang feat: Add browser language detector to automatically switch to default browser lang Aug 2, 2023
@anshgoyalevil anshgoyalevil changed the title feat: Add browser language detector to automatically switch to default browser lang feat: add browser language detector to automatically switch to default browser lang Aug 2, 2023
@github-actions
Copy link

github-actions bot commented Aug 2, 2023

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 27
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🔴 PWA 30

Lighthouse ran on https://deploy-preview-2022--asyncapi-website.netlify.app/

Copy link
Member

@magicmatatjahu magicmatatjahu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it's good :) However, please remove the prefix in the current website, when user go to the site. Atm we are redirecting from root to the en by default. We will enable that at the end of epic.

image

lib/browserLanguageDetector.js Outdated Show resolved Hide resolved
@anshgoyalevil
Copy link
Member Author

Thanks for reviewing @magicmatatjahu 😄

I have made the required changes.
The website wouldn't be redirected to the /en lang as I have commented the function which controls this behavior. Would enable that at the end of epic.

@magicmatatjahu
Copy link
Member

@anshgoyalevil Thanks! :)

@magicmatatjahu
Copy link
Member

/rtm

@asyncapi-bot asyncapi-bot merged commit 7eda8a3 into asyncapi:master Aug 7, 2023
@anshgoyalevil anshgoyalevil deleted the browser branch September 8, 2023 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add browser language detector to automatically switch to default browser lang
4 participants