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

Preferred language when not logged in #8937

Closed
maboroshin opened this issue Mar 16, 2023 · 7 comments · Fixed by #10387
Closed

Preferred language when not logged in #8937

maboroshin opened this issue Mar 16, 2023 · 7 comments · Fixed by #10387
Assignees
Labels
enhancement Adding or requesting a new feature. good first issue Opportunity for newcoming contributors. help wanted Extra attention is needed.
Milestone

Comments

@maboroshin
Copy link

maboroshin commented Mar 16, 2023

Describe the problem

Preferred target language not detected when not logged in.

Describe the solution you'd like

Display the browser's display language at the beginning of the language list. Same as when login.

Additional context

"日本語 (Japanese)" is displayed at the bottom of the list due to the rules of Japanese. They have to scroll to the bottom every time. The languages at the bottom in Unicode order have the same problem.

@nijel nijel added enhancement Adding or requesting a new feature. help wanted Extra attention is needed. good first issue Opportunity for newcoming contributors. labels Mar 16, 2023
@github-actions
Copy link

This issue seems to be a good fit for newbie contributors. You are welcome to contribute to Weblate! Don't hesitate to ask any questions you would have while implementing this.

You can learn about how to get started in our contributors documentation.

@nijel
Copy link
Member

nijel commented Mar 16, 2023

The logic is here:

def get_translation_order(self, translation) -> int:
"""Returns key suitable for ordering languages based on user preferences."""
language = translation.language
if language.pk in self.primary_language_ids:
return 0
if language.pk in self.secondary_language_ids:
return 1
if translation.is_source:
return 2
return 3

Adding the current interface language is the easiest path, but that would limit it to only languages in which Weblate is translated. Building on top of Language.objects.get_request_language is probably a more generic approach.

@dankrzeminski32
Copy link
Contributor

Hey @nijel,

I'm starting work on this. What do you mean by "Adding the current interface language"?

If extending on Language.objects.get_request_language, do we catch Language.DoesNotExist and create a new language?

@nijel
Copy link
Member

nijel commented Apr 25, 2023

get_request_language already catches DoesNotExist. Creating new languages there is not useful – we would rather not pollute the database with random stuff the user sends in an HTTP header.

@dankrzeminski32
Copy link
Contributor

dankrzeminski32 commented Apr 25, 2023

So if the user is not logged in,

1.) Get language from header using get_request_language and match it to our db record
2.) Prioritize this above all other languages in get_translation_order

Let me know if that sounds right.

@nijel
Copy link
Member

nijel commented Apr 26, 2023

Yes, get_translation_order will need to receive request as well to be able to get that information.

@nijel nijel added this to the 5.2 milestone Sep 12, 2023
@nijel nijel self-assigned this Nov 9, 2023
nijel added a commit to nijel/weblate that referenced this issue Nov 9, 2023
…dering

This shows more prominently translations user understands.

Fixes WeblateOrg#8937
nijel added a commit to nijel/weblate that referenced this issue Nov 9, 2023
…dering

This shows more prominently translations user understands.

Fixes WeblateOrg#8937
nijel added a commit to nijel/weblate that referenced this issue Nov 9, 2023
…dering

This shows more prominently translations user understands.

Fixes WeblateOrg#8937
nijel added a commit that referenced this issue Nov 9, 2023
…dering

This shows more prominently translations user understands.

Fixes #8937
Copy link

github-actions bot commented Nov 9, 2023

Thank you for your report; the issue you have reported has just been fixed.

  • In case you see a problem with the fix, please comment on this issue.
  • In case you see a similar problem, please open a separate issue.
  • If you are happy with the outcome, don’t hesitate to support Weblate by making a donation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adding or requesting a new feature. good first issue Opportunity for newcoming contributors. help wanted Extra attention is needed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants