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

[docs] Fix language cookie #23324

Merged
merged 3 commits into from Oct 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions docs/pages/_app.js
Expand Up @@ -51,13 +51,11 @@ function LanguageNegotiation() {
React.useEffect(() => {
const { userLanguage: userLanguageUrl, canonical } = pathnameToLanguage(router.asPath);
const preferedLanguage =
getCookie('userLanguage') !== 'noDefault' && userLanguage === 'en'
? acceptLanguage.get(navigator.language)
: userLanguage;
getCookie('userLanguage') || acceptLanguage.get(navigator.language) || userLanguage;

if (preferedLanguage !== userLanguage) {
if (userLanguageUrl === 'en' && userLanguage !== preferedLanguage) {
window.location = preferedLanguage === 'en' ? canonical : `/${preferedLanguage}${canonical}`;
} else if (userLanguageUrl !== userLanguage) {
} else if (userLanguage !== userLanguageUrl) {
dispatch({ type: ACTION_TYPES.OPTIONS_CHANGE, payload: { userLanguage: userLanguageUrl } });
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Never actually seem to reach this branch, but then not sure where userLanguage is set otherwise?

}, []); // eslint-disable-line react-hooks/exhaustive-deps
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/AppFrame.js
Expand Up @@ -158,7 +158,7 @@ function AppFrame(props) {
};
const handleLanguageMenuClose = (event) => {
if (event.currentTarget.nodeName === 'A') {
document.cookie = `userLanguage=noDefault;path=/;max-age=31536000`;
document.cookie = `userLanguage=${event.currentTarget.lang};path=/;max-age=31536000`;
}
setLanguageMenu(null);
};
Expand Down