Skip to content

fix: fix issues with LANGUAGE_CODE [BB-4823] [OSPR-6178] - #29122

Closed
Cup0fCoffee wants to merge 2 commits into
openedx:open-release/lilac.masterfrom
open-craft:maxim/bb-4823-fix-issues-with-LANGUAGE-CODE
Closed

fix: fix issues with LANGUAGE_CODE [BB-4823] [OSPR-6178]#29122
Cup0fCoffee wants to merge 2 commits into
openedx:open-release/lilac.masterfrom
open-craft:maxim/bb-4823-fix-issues-with-LANGUAGE-CODE

Conversation

@Cup0fCoffee

@Cup0fCoffee Cup0fCoffee commented Oct 26, 2021

Copy link
Copy Markdown
Contributor

Description

This PR fixes the issues of #28502, which are described this comment.

#28502 introduced the change that allows to set LANGUAGE_CODE in site configurations, which made it possible to change translation of the entire site for all learners from Django admin panel. However, the implemented solution didn't work in all cases:

  • In legacy UI in some instances (most of the times it would be when a language code would be required to format a date) would use the language which was set in users' preferences, or if none were set, would fallback to English
  • MFEs would also use the language which was selected in users' preferences, because it would read the values that were set in cookies, and the original solution only modified the values in a session

Before (the date is not in the correct format):
Screenshot 2021-10-28 at 00-53-08 لوحة المعلومات Your Platform Name Here
After (the date is now in the correct format):
Screenshot 2021-10-28 at 00-47-41 لوحة المعلومات Your Platform Name Here

Supporting information

BB-4823
OSPR-6178
#28502

Testing instructions

  • Change/set LANGUAGE_CODE site config to ar at http://localhost:18000/admin/site_configuration/siteconfiguration/ (it might take some time to take effect because of caching; you can add SITE_CACHE_TTL = 0 to lms/envs/private.py to remove caching)
  • Go to http://localhost:18000/dashboard and check that the dates for the courses the user is enrolled in are correctly formatted (see screenshots above)
  • Go to http://localhost:1997 (frontend-app-account) and check that it's displayed in Arabic; check that setting the language (second dropdown from the bottom) to English doesn't change the language

Deadline

"None"

Concerns

After setting LANGUAGE_CODE for a site, users who visited that site will have language cookies with the same value as LANGUAGE_CODE in site configuration, which might create the following problems:

  • If LANGUAGE_CODE is removed after, the middleware will use the values from cookies to update users' preferences, which might end up messing up preferences for users that don't want that language be saved to their preferences.
  • If cookies that store value for language have domain set to a value which allows subdomains or other domains have access to it, on those domains (if other sites don't have LANGUAGE_CODE set) the language in users' preferences will be overwritten. Since edX Sites are normally hosted on different domains and default value for SESSION_COOKIE_DOMAIN settings is an empty string, this shouldn't be a problem, but in certain situations it can cause problems.

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. labels Oct 26, 2021
@openedx-webhooks

openedx-webhooks commented Oct 26, 2021

Copy link
Copy Markdown

Thanks for the pull request, @Cup0fCoffee! I've created OSPR-6178 to keep track of it in JIRA, where we prioritize reviews. Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@Cup0fCoffee
Cup0fCoffee force-pushed the maxim/bb-4823-fix-issues-with-LANGUAGE-CODE branch from 10e2c94 to 45e1fec Compare October 27, 2021 18:09
When side-wide language is set via LANGUAGE_CODE site configuration,
some elements of legacy UI still use the language set in user
preferences (or None, which fallsback to 'en' if nothing is set in
preferences). The expectation is that everything should be translated to
the language which is set in the site configuration.

In legacy UI (i.e. templates) the code of the current language sometimes
is needed, and in these cases `user_language` variable from the context
is used. The value for that variable is inserted via context processor,
which takes the value from the user preferences.

The solution modifies the context processor to check if there is a
language set in site configuration, and if there is, send that value,
instead of whatever value there was in user peferences.
When a site-wide language is set in site configurations, the desired
result is that MFEs use that language over the one which is set in user
preferences (or if None is set, it would fallback to 'en').

Since the MFEs use language value from cookies to determine which
language to use, and the existing solution was only modifying the
language in the session, and not overwrite the value in the cookies, the
MFEs would use language set in users' preferences (or 'en' if nothing
was set).

This commit removes the existing solution and implements a new one in
the middleware that sets language values in cookies based on the values
set in users' preferences. The modified middleware is going to check if
there is a site-wide language set in site configurations, and if it is,
will use that value over the one which is set in users' preferences.

Additionally, if site-wide language is set, the middleware won't save
the language which is passed in cookies as the user preference, to not
overwrite the user preference for other sites, where this site
configuration doesn't apply.
@Cup0fCoffee
Cup0fCoffee force-pushed the maxim/bb-4823-fix-issues-with-LANGUAGE-CODE branch from 45e1fec to 1a93925 Compare October 27, 2021 19:26
@natabene

Copy link
Copy Markdown
Contributor

@Cup0fCoffee Thank you for your contribution. Is this ready for our review?

@Cup0fCoffee Cup0fCoffee changed the title [WIP] fix: fix issues with LANGUAGE_CODE [BB-4823] fix: fix issues with LANGUAGE_CODE [BB-4823] [OSPR-6178] Oct 27, 2021
@openedx-webhooks openedx-webhooks added needs triage and removed waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. labels Oct 27, 2021
@Cup0fCoffee

Copy link
Copy Markdown
Contributor Author

Closing this PR in favor of creating two separate and smaller PRs.

@Cup0fCoffee Cup0fCoffee closed this Nov 3, 2021
@openedx-webhooks

Copy link
Copy Markdown

@Cup0fCoffee Even though your pull request wasn’t merged, please take a moment to answer a two question survey so we can improve your experience in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U rejected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants