-
Notifications
You must be signed in to change notification settings - Fork 38
Choose best language from the user browser #1281
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
base: master
Are you sure you want to change the base?
Choose best language from the user browser #1281
Conversation
|
@dodoels can you do a final check on this as you added the i18n feature initially 🙏 |
| return lang; | ||
| }; | ||
|
|
||
| const languageMap = new Map<string, string>([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to explictly define an utility function to do this which introduces extra complexity when we get rid of Wowhead in the future.
The existing languagedetector API from i18next-browser-languagedetector can already do the job.
Simply do
import LanguageDetector from 'i18next-browser-languagedetector';
export const detectBrowserLang = (): string => {
const detector = new LanguageDetector();
const detectedLang = detector.detect() as string;
const baseLang = detectedLang.split('-')[0].toLowerCase();
return baseLang in supportedLanguages ? baseLang : 'en'; // this is important, because we define what languages to support and compatible with Wowhead APIs
};
and finally just call this function in getLang()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yea true!
No description provided.