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

[i18n] Save preferred_language for auth user in db #3103

Merged
merged 10 commits into from Oct 25, 2023

Conversation

rajatvijay
Copy link
Contributor

@rajatvijay rajatvijay commented Jul 27, 2023

Relates #2927

Technical details

This PR does the following things -

  1. Adds Locale middleware in BE
  2. Add a preferred_language attribute in the users model and serializers. Migrations for this field.
  3. Adds the Preferred Language dropdown in the user's profile page.
  4. Load the changed preferred language's translations from the profile page dynamically, on the client side.

Screenshots

users_lang_in_db.mp4

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the develop branch of the repository
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no
    visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@rajatvijay rajatvijay changed the title I18n save lang for auth user [i18n] Save preferred_language for auth user in db Jul 27, 2023
@rajatvijay rajatvijay added the pr-status: review A PR awaiting review label Jul 27, 2023
@rajatvijay rajatvijay added this to the v0.1.3 milestone Jul 27, 2023
@rajatvijay rajatvijay marked this pull request as ready for review July 27, 2023 10:02
@rajatvijay
Copy link
Contributor Author

@ghislaineguerin @kgodey assigned you for a product related review.

@ghislaineguerin
Copy link
Contributor

@rajatvijay Looks good to me.

@kgodey
Copy link
Contributor

kgodey commented Jul 28, 2023

Could we name the option "UI Language" or "Display Language"? I think that's clearer than "Preferred Language". I'd also update the backend name to match.

Otherwise, looks good.

@seancolsen
Copy link
Contributor

"Preferred Language" and "Display Language" both seem fine to me. But "UI Language" seems like is has the potential to confuse some people who are not familiar with that acronym.

@kgodey
Copy link
Contributor

kgodey commented Jul 31, 2023

Let's do "Display Language" then.

Copy link
Contributor

@silentninja silentninja left a comment

Choose a reason for hiding this comment

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

I reviewed the changes to the backend code and it looks good to me!

@silentninja silentninja removed their assignment Aug 1, 2023
Copy link
Contributor

@seancolsen seancolsen left a comment

Choose a reason for hiding this comment

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

I've noted a couple small comments on the diff, but a larger issue here is that we'll need to find a way to hide this UI before we can merge it. Otherwise we should hold off on merging until we have the full Japanese translation available.

mathesar_ui/src/api/users.ts Outdated Show resolved Hide resolved
@seancolsen seancolsen removed their assignment Aug 11, 2023
@seancolsen seancolsen added pr-status: revision A PR awaiting follow-up work from its author after review and removed pr-status: review A PR awaiting review labels Aug 11, 2023
@rajatvijay rajatvijay modified the milestones: v0.1.3, v0.1.4 Aug 17, 2023
@rajatvijay
Copy link
Contributor Author

Commented out the Display Language select on the profile page 36d314d

@rajatvijay rajatvijay assigned seancolsen and unassigned rajatvijay Sep 6, 2023
@rajatvijay rajatvijay added pr-status: review A PR awaiting review and removed pr-status: revision A PR awaiting follow-up work from its author after review labels Sep 6, 2023
Copy link
Contributor

@seancolsen seancolsen left a comment

Choose a reason for hiding this comment

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

Looks good now 👍🏻

@seancolsen
Copy link
Contributor

I'm holding off merge since this is stacked on top of #3102. @rajatvijay feel free to merge this yourself once that PR is merged.

@seancolsen seancolsen removed their assignment Sep 11, 2023
@seancolsen seancolsen added needs: unblocking Blocked by other work and removed pr-status: review A PR awaiting review labels Sep 11, 2023
@rajatvijay rajatvijay self-assigned this Sep 22, 2023
@seancolsen seancolsen modified the milestones: v0.1.4, Next release Oct 2, 2023
@pavish pavish mentioned this pull request Oct 16, 2023
7 tasks
Base automatically changed from i18n-load-en-translations-parallely to develop October 25, 2023 16:40
@seancolsen
Copy link
Contributor

I'm trying to move this PR along in order to reduce our PR backlog so I spent some time resolving git merge conflicts in several files. Even though I'm not familiar with the code changes in this PR, the git conflicts seemed straightforward enough that I resolved them in c0b6cb3.

However, when I try to run Mathesar after that commit, the service container prints:

django.core.management.base.CommandError: Conflicting migrations detected; multiple leaf nodes in the migration graph: (0005_user_display_language, 0008_auto_20230921_1834 in mathesar).
mathesar_service_dev | To fix them run 'python manage.py makemigrations --merge'

In an attempt to fix this problem, I ran the following command:

sudo docker exec mathesar_service_dev sh -c "python manage.py makemigrations --merge"

That gave me this output, which seems quite strange:

Merging mathesar
  Branch 0008_auto_20230921_1834
    - Add field sheet_name to datafile
    - Remove field sheet_name from datafile
    - Add field sheet_index to datafile
    - Raw SQL operation
    - Add field db_name to database
    - Add field editable to database
    - Add field host to database
    - Add field password to database
    - Add field port to database
    - Add field username to database
  Branch 0005_user_display_language
    - Add field display_language to user

Merging will only work if the operations printed above do not conflict
with each other (working on different fields or models)
Do you want to merge these migration branches? [y/N] Traceback (most recent call last):
  File "/code/manage.py", line 22, in <module>
    main()
  File "/code/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/makemigrations.py", line 133, in handle
    return self.handle_merge(loader, conflicts)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/makemigrations.py", line 276, in handle_merge
    if questioner.ask_merge(app_label):
  File "/usr/local/lib/python3.9/site-packages/django/db/migrations/questioner.py", line 200, in ask_merge
    return self._boolean_input(
  File "/usr/local/lib/python3.9/site-packages/django/db/migrations/questioner.py", line 87, in _boolean_input
    result = input("%s " % question)
EOFError: EOF when reading a line

Aside from the "Conflicting migrations detected" message, Mathesar appears to function normally.

I would like a back-end engineer to look into this.

@seancolsen
Copy link
Contributor

I figured it out — it was an issue with accepting user input when using docker exec. I was able to generate a new migration by running:

sudo docker exec mathesar_service_dev sh -c "python manage.py makemigrations --merge --no-input"

I committed that migration in 825a36f

@seancolsen seancolsen added this pull request to the merge queue Oct 25, 2023
@seancolsen
Copy link
Contributor

If all the tests pass, I'm assuming we're good to go here, so I've queued this to merge now.

Merged via the queue into develop with commit c2059cc Oct 25, 2023
14 of 17 checks passed
@seancolsen seancolsen deleted the i18n-save-lang-for-auth-user branch October 25, 2023 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: unblocking Blocked by other work
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants