-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix #3551: Manually set cookie value during language change #3622
Conversation
@kevinlee12 -- do you remember why you introduced the base tag in this commit? 2b8e97b |
Codecov Report
@@ Coverage Diff @@
## develop #3622 +/- ##
===========================================
- Coverage 45.03% 45.03% -0.01%
===========================================
Files 261 261
Lines 20219 20220 +1
Branches 3157 3157
===========================================
Hits 9106 9106
- Misses 11113 11114 +1
Continue to review full report at Codecov.
|
Ah, that was needed so that we can manipulate the history for the search function (since we're adding browser history entries without reloading the page). More specifically, it was changing the history as the learner was typing in queries into the search bar in the library. The tag itself was to segregate the search page into it's own "app" so that this would work. |
After further investigation, I found that cookie path is affected by the base url: https://docs.angularjs.org/api/ngCookies/provider/$cookiesProvider#defaults |
Thanks, @muxout. That's a great find, and I think it explains some of the existing behaviour! It seems like that's a global default, though. I wonder whether it may be better to investigate the alternative instead, which is to make the library/search page function well without needing to overwrite the base tag. What do you think? |
@muxout How is this going? Did you see Sean's comment above? |
core/templates/dev/head/i18n.js
Outdated
@@ -90,6 +90,11 @@ oppia.controller('I18nFooter', [ | |||
$http.put(siteLanguageUrl, { | |||
site_language_code: $scope.currentLanguageCode | |||
}); | |||
} else { | |||
// This is a workaround for the library page as the base url |
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.
I think this approach is reasonable, actually. But I'm a little confused about when it's applied. From the conditional, it seems to be applied when the user is not logged in (as opposed to when the user is on the library page)?
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.
This issue only affects users who are not logged in, as per #3551. I thought this might be the easiest workaround.
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.
Oh, sorry, now I get it!
Yep, makes sense. My understanding is that sometimes $translate sets this cookie automatically, but we are setting it manually here in all cases for safety's sake. Is that right? If so, that makes sense to me.
Can we explain this a bit more in the comment so that future devs have context? At the moment it reads like "this is something to be applied only in the library page", which is why I asked the question I did.
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 yes that's what I meant. Agreed.
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, sorry, I meant something a bit different. How about:
// $translate.use() sets a cookie for the translation language, but does so using the
// page's base URL as the cookie path. However, the base URL is modified in pages
// like /library, thus causing the cookie path to change; in such cases, the user's
// preferences are not picked up by other pages. To avoid this, we manually set
// the cookie using the '/' path each time a non-logged-in user changes their
// site language.
I think this provides the full context (i.e. a bit more info on the cookie path and what's really going on here) that would be useful to devs.
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.
Agreed, it's much clearer.
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.
Just a few small comments. I think this looks fantastic, and solves a long-standing issue. Thanks very much, @muxout!
core/templates/dev/head/i18n.js
Outdated
@@ -90,6 +90,11 @@ oppia.controller('I18nFooter', [ | |||
$http.put(siteLanguageUrl, { | |||
site_language_code: $scope.currentLanguageCode | |||
}); | |||
} else { | |||
// This is a workaround for the library page as the base url |
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.
Oh, sorry, now I get it!
Yep, makes sense. My understanding is that sometimes $translate sets this cookie automatically, but we are setting it manually here in all cases for safety's sake. Is that right? If so, that makes sense to me.
Can we explain this a bit more in the comment so that future devs have context? At the moment it reads like "this is something to be applied only in the library page", which is why I asked the question I did.
core/templates/dev/head/i18n.js
Outdated
@@ -90,6 +90,11 @@ oppia.controller('I18nFooter', [ | |||
$http.put(siteLanguageUrl, { | |||
site_language_code: $scope.currentLanguageCode | |||
}); | |||
} else { | |||
// This is a workaround for the library page as the base url | |||
// changes the default cookie path |
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.
Nit: End comments with a period.
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.
Done
core/templates/dev/head/i18n.js
Outdated
} else { | ||
// This is a workaround for the library page as the base url | ||
// changes the default cookie path | ||
$cookies.put('NG_TRANSLATE_LANG_KEY', |
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.
Nit: if multiline strings are contained in (...), break after the first (
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.
Done
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.
LGTM. Thanks @muxout!
* upstream/develop: (39 commits) Add a one-off job to list which explorations use gadgets; remove old fallbacks job. (oppia#3717) Fix oppia#2998 implement collection skills update commands (oppia#3710) Improvements and bug fixes to changes introduced by PR oppia#3671 (oppia#3684) Fix oppia#3688: refactoring ExplorationStatusHandler to remove unpublish and publicize functionality as it is not called from frontend. (oppia#3715) fix oppia#3698: Shift exception handling for NotLoggedInException so that it does not generate log errors. (oppia#3714) Revert "Fix oppia#3707 Change text of collection learner view "start here"" (oppia#3713) Fix oppia#3701 Fixed Continue button name issue (oppia#3711) Fix oppia#3467: Introduce re-training and add_to_training_queue methods (oppia#3650) Fix oppia#3707 Change text of collection learner view "start here" (oppia#3700) Audio fixes: make audio download URL safe; don't show flagging modal if all translations are flagged; use templateUrl for modals. (oppia#3709) Learner audio updates (oppia#3705) Move hint button to left corner for supplemental cards (oppia#3702) Make the representation of the learner's 'Continue' answer more conversational. (oppia#3675) Add editor for audio translations (oppia#3692) Fix oppia#3686 fixed text overflow for contributors list (oppia#3697) Fix oppia#3551: Manually set cookie value during language change (oppia#3622) Learner view audio translations (oppia#3681) The sixth milestone of the learner dashboard. (oppia#3680) Routine update of translations. (oppia#3685) SiteWide ACL Refactor: Milestone 3.1 (oppia#3682) ...
When a new language is selected the language code is stored in a cookie. But when the same piece of code is invoked from the library page the value in the cookie doesn't change.
This seem to fix the issue but I haven't quite figured out why. Maybe someone familiar with Angular should have a look.