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

Feat: language picker #6716

Draft
wants to merge 50 commits into
base: master
Choose a base branch
from
Draft

Feat: language picker #6716

wants to merge 50 commits into from

Conversation

mind-ar
Copy link
Collaborator

@mind-ar mind-ar commented Feb 21, 2024

this PR allows the end user to manually select the UI language
tasks:

  • Add Picker
  • Remove Duplicated Languages
  • Save user's choice in localStore
  • migrate locale list to api
  • generate locale name in correct language
  • allow implementing custom portal.json
  • add tests

Summary by CodeRabbit

Summary of changes

  • New Features
    • Introduced a language selection feature across the application, allowing users to choose their preferred language.
    • Enhanced locale management with the addition of sorting languages based on locale criteria and handling language fallbacks.
    • Increased timeout duration for service readiness checks to improve stability.
  • Refactor
    • Updated and optimized locale-related functionalities, including the handling of available languages and namespace defaults.
    • Refactored local storage access for improved efficiency.
  • Chores
    • Added new configuration settings for TypeScript template files.
    • Introduced new constants and data structures for better locale and language management.

@authelia
Copy link

authelia bot commented Feb 21, 2024

Artifacts

These changes are published for testing on Buildkite, DockerHub and GitHub Container Registry.

Docker Container

  • docker pull authelia/authelia:feat-i18n-picker
  • docker pull ghcr.io/authelia/authelia:feat-i18n-picker

Copy link
Contributor

coderabbitai bot commented Feb 21, 2024

Important

Auto Review Skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent updates focus on enhancing language support and configuration across the application. Key changes include adding support for TypeScript template files, refining language sorting based on locale criteria, removing default locale constants, and extending timeout durations for service readiness checks. Additionally, new functionalities for handling locales, including a language selector component and utilities for language information retrieval and storage management, have been introduced to improve the user experience in language selection and application internationalization.

Changes

File(s) Summary
.editorconfig Added new configuration for *.ts.tmpl files to use space indentation.
cmd/authelia-gen/... Updated to sort languages.RealLng based on locale criteria, removed localeDefault and localeNamespaceDefault constants, added Parent field to Language struct.
internal/suites/environment.go Increased timeout duration from 90 to 120 seconds for service readiness checks.
internal/server/..., internal/utils/... Added language alias mapping, new locales list handler, constants for locales and file extensions, and functionalities for language information retrieval and management.
web/src/... Introduced a LanguageSelector component, updated local storage detection, added language constants, and integrated language selection in the login portal.

In code we trust,
Languages dance and adjust,
Rabbit's joy in code's embrace,
Changes bring a whimsical grace,
Tech symphony in every case.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@mind-ar mind-ar marked this pull request as draft February 21, 2024 01:35
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4c2d22e and 1710357.
Files selected for processing (6)
  • .editorconfig (1 hunks)
  • cmd/authelia-gen/templates/web_i18n_index.ts.tmpl (1 hunks)
  • internal/suites/environment.go (4 hunks)
  • web/src/components/LanguageSelector.tsx (1 hunks)
  • web/src/i18n/index.ts (1 hunks)
  • web/src/views/LoginPortal/FirstFactor/FirstFactorForm.tsx (3 hunks)
Files skipped from review due to trivial changes (1)
  • .editorconfig
Additional comments: 7
cmd/authelia-gen/templates/web_i18n_index.ts.tmpl (1)
  • 59-63: The addition of the supportedLngsNames constant array is correctly implemented and aligns with the PR's objectives to enhance language selection functionality. The syntax and structure are consistent with the file's purpose as a template for generating TypeScript code.
internal/suites/environment.go (4)
  • 44-44: The increase in timeout duration from 90 seconds to 120 seconds for the waitUntilAutheliaBackendIsReady function is correctly implemented and aligns with the PR's objectives to improve the reliability of service readiness checks.
  • 53-53: The increase in timeout duration from 90 seconds to 120 seconds for the waitUntilAutheliaFrontendIsReady function is correctly implemented and aligns with the PR's objectives to improve the reliability of service readiness checks.
  • 62-62: The increase in timeout duration from 90 seconds to 120 seconds for the waitUntilK3DIsReady function is correctly implemented and aligns with the PR's objectives to improve the reliability of service readiness checks.
  • 71-71: The increase in timeout duration from 90 seconds to 120 seconds for the waitUntilSambaIsReady function is correctly implemented and aligns with the PR's objectives to improve the reliability of service readiness checks.
web/src/i18n/index.ts (1)
  • 120-156: The addition of the supportedLngsNames constant array is correctly implemented and aligns with the PR's objectives to enhance language selection functionality. The syntax, structure, and comprehensive list of languages are consistent with the file's purpose and the overall goal of providing a flexible language selection feature.
web/src/views/LoginPortal/FirstFactor/FirstFactorForm.tsx (1)
  • 48-54: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [11-110]

The integration of the LanguageSelector component into the FirstFactorForm is correctly implemented and aligns with the PR's objectives to enhance user experience by allowing language selection at the login stage. The use of React hooks for state management and the strategic placement of the component for visibility and accessibility are well-executed.

web/src/components/LanguageSelector.tsx Outdated Show resolved Hide resolved
Copy link

codecov bot commented Feb 21, 2024

Codecov Report

Attention: Patch coverage is 74.06484% with 104 lines in your changes are missing coverage. Please review.

Project coverage is 73.60%. Comparing base (8ce3659) to head (34ca7a5).

❗ Current head 34ca7a5 differs from pull request most recent head 2f07394. Consider uploading reports for the commit 2f07394 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6716      +/-   ##
==========================================
- Coverage   73.65%   73.60%   -0.06%     
==========================================
  Files         346      349       +3     
  Lines       29973    30258     +285     
  Branches      839      857      +18     
==========================================
+ Hits        22078    22272     +194     
- Misses       7022     7096      +74     
- Partials      873      890      +17     
Flag Coverage Δ
backend 74.50% <74.40%> (-0.05%) ⬇️
frontend 65.91% <73.14%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
internal/configuration/validator/configuration.go 100.00% <100.00%> (ø)
internal/server/handlers.go 91.83% <100.00%> (+0.04%) ⬆️
web/src/i18n/detectors/localStorageCustom.ts 85.71% <100.00%> (ø)
web/src/i18n/index.ts 100.00% <100.00%> (ø)
web/src/services/Api.ts 100.00% <100.00%> (ø)
web/src/services/LocaleInformation.ts 100.00% <100.00%> (ø)
.../views/LoginPortal/FirstFactor/FirstFactorForm.tsx 55.28% <73.33%> (+2.07%) ⬆️
web/src/utils/localStorage.ts 64.70% <64.70%> (ø)
internal/configuration/validator/custom_locales.go 35.71% <35.71%> (ø)
web/src/components/LanguageSelector.tsx 67.24% <67.24%> (ø)
... and 2 more

... and 23 files with indirect coverage changes

@mind-ar
Copy link
Collaborator Author

mind-ar commented Feb 21, 2024

imagen
imagen
imagen

@mind-ar
Copy link
Collaborator Author

mind-ar commented Feb 21, 2024

HI! this PR is almost ready for review, but there's one problem: there are redundant locales that result in duplicated entries in the language picker, for example
imagen
i can filter by locale (the two first letters) but that can be harmful for cases that is needed different variants of the same language

Copy link

netlify bot commented Feb 22, 2024

Deploy Preview for authelia-staging ready!

Name Link
🔨 Latest commit 2f07394
🔍 Latest deploy log https://app.netlify.com/sites/authelia-staging/deploys/661fa6d85aa1d600084071df
😎 Deploy Preview https://deploy-preview-6716--authelia-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mind-ar mind-ar marked this pull request as ready for review February 22, 2024 01:05
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 1710357 and ad18130.
Files ignored due to path filters (1)
  • docs/data/languages.json is excluded by: !**/*.json
Files selected for processing (8)
  • cmd/authelia-gen/cmd_locales.go (2 hunks)
  • cmd/authelia-gen/templates/web_i18n_index.ts.tmpl (1 hunks)
  • cmd/authelia-gen/types.go (1 hunks)
  • web/src/components/LanguageSelector.tsx (1 hunks)
  • web/src/i18n/detectors/localStorageCustom.ts (1 hunks)
  • web/src/i18n/index.ts (1 hunks)
  • web/src/utils/localStorage.ts (1 hunks)
  • web/src/views/LoginPortal/FirstFactor/FirstFactorForm.tsx (4 hunks)
Files skipped from review as they are similar to previous changes (4)
  • cmd/authelia-gen/templates/web_i18n_index.ts.tmpl
  • web/src/components/LanguageSelector.tsx
  • web/src/i18n/index.ts
  • web/src/views/LoginPortal/FirstFactor/FirstFactorForm.tsx
Additional comments: 5
web/src/i18n/detectors/localStorageCustom.ts (1)
  • 3-3: The import of localStorageAvailable from @utils/localStorage is correctly implemented. Ensure that the utility function behaves as expected across different environments, especially considering scenarios where local storage might be restricted or unavailable.
web/src/utils/localStorage.ts (1)
  • 5-19: The localStorageAvailable function is well-implemented, correctly checking for both the presence and usability of local storage. This approach effectively mitigates potential exceptions in environments where local storage is restricted.
cmd/authelia-gen/cmd_locales.go (2)
  • 173-173: The addition of languages.RealLng and its subsequent sorting is a thoughtful enhancement, improving the organization of language options for users. This change positively impacts user experience by ensuring a logical and consistent presentation of language choices.
  • 220-222: The sorting logic applied to languages.RealLng is correctly implemented, ensuring that the default language is prioritized and other languages are sorted alphabetically. This approach enhances the user experience by providing a more intuitive selection process.
cmd/authelia-gen/types.go (1)
  • 100-100: The addition of the RealLng field to the Languages struct is a necessary and well-implemented change to support improved language organization and selection. This change aligns with the project's objectives of enhancing user experience through more intuitive language options.

web/src/utils/localStorage.ts Outdated Show resolved Hide resolved
@james-d-elliott
Copy link
Member

james-d-elliott commented Feb 22, 2024

I'll take a look at this once the conflicting changes are merged. I suspect we'll want something within the settings area too. Looks mostly good however, would like to allow some additional things in general.

@nightah
Copy link
Member

nightah commented Feb 22, 2024

HI! this PR is almost ready for review, but there's one problem: there are redundant locales that result in duplicated entries in the language picker, for example imagen i can filter by locale (the two first letters) but that can be harmful for cases that is needed different variants of the same language

Why don't we group them with the top-level language code and include the language codes in the visual display, alongside the "clean name"?

mind-ar and others added 2 commits February 22, 2024 10:36
Co-authored-by: James Elliott <james-d-elliott@users.noreply.github.com>
Signed-off-by: Manuel Nuñez <10672208+mind-ar@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ad18130 and c623a6e.
Files selected for processing (1)
  • cmd/authelia-gen/types.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • cmd/authelia-gen/types.go

@mind-ar
Copy link
Collaborator Author

mind-ar commented Feb 22, 2024

Why don't we group them with the top-level language code and include the language codes in the visual display, alongside the "clean name"?

@nightah something like this?
imagen

ase enter the commit message for your changes. Lines starting
@mind-ar
Copy link
Collaborator Author

mind-ar commented Feb 22, 2024

I'll take a look at this once the conflicting changes are merged. I suspect we'll want something within the settings area too. Looks mostly good however, would like to allow some additional things in general.

Added an option to the component to switch between two modes, so it can be used as part of a form:

Select mode (picker = false)
imagen
Picker mode (picker = true)
imagen

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c623a6e and 0ebd33f.
Files ignored due to path filters (1)
  • docs/data/languages.json is excluded by: !**/*.json
Files selected for processing (4)
  • cmd/authelia-gen/cmd_locales.go (4 hunks)
  • web/src/components/LanguageSelector.tsx (1 hunks)
  • web/src/i18n/index.ts (1 hunks)
  • web/src/views/LoginPortal/FirstFactor/FirstFactorForm.tsx (4 hunks)
Files skipped from review as they are similar to previous changes (4)
  • cmd/authelia-gen/cmd_locales.go
  • web/src/components/LanguageSelector.tsx
  • web/src/i18n/index.ts
  • web/src/views/LoginPortal/FirstFactor/FirstFactorForm.tsx

@james-d-elliott
Copy link
Member

Yea I ran into this issue too at some point, can't recall how I handled it. My recollection is there are actually 3 total. no, nb, and nn-NO. The first refers to either Norwegian locale, second is Bokmal, and third is Nynorsk. I'm surprised go doesn't have a field for this.. let me check in the debugger.

@mind-ar
Copy link
Collaborator Author

mind-ar commented Mar 8, 2024

Yea I ran into this issue too at some point, can't recall how I handled it. My recollection is there are actually 3 total. no, nb, and nn-NO. The first refers to either Norwegian locale, second is Bokmal, and third is Nynorsk. I'm surprised go doesn't have a field for this.. let me check in the debugger.

after some research, i found that currently go/x/text/language uses CLDR v32.
imagen
Before v39, nb and nn were independent base locales and no was an alias of nb. on v39 they unified both nb and nn under no

As we have no-NO and nb-NO, and they are the same, my suggestion is to unify both locales into nb and, if a contributor wants to add Nynorsk, we add nn, until go updates to v39 of CLDR (i don't know if this breaks something in crowdin)

Here's some related information:

@james-d-elliott
Copy link
Member

james-d-elliott commented Mar 9, 2024

The first refers to either Norwegian locale, second is Bokmal, and third is Nynorsk. I'm surprised go doesn't have a field for this.. let me check in the debugger.

Yeah this is what I meant here, I'm fine with whatever path we take here. We just have to ensure that the cases for browsers only advertising macrolanguages
(en, no, zh, etc) are handled by one of the microlanguages, and that the relevant generate functions work with this too so we don't have to manually handle this each time languages are added (it will become a nightmare to manage pretty quickly).

You can experiment with the language matching using most browsers to change the requested language. As long as the automatic functionality remains intact and the list makes logical sense then I'm fine with it. We can as I said make fixes later if it's not quite right, and when we get the second language add logic to handle this from the frontend.

Regarding caching, we can use the ETag / If-None-Match process to ensure the request is only processed when the values change. If we do this when/if we add logic to handle fs changes (i.e. locales added) then we can determine there is an update to be sent to clients. Though this can be added later too.

@mind-ar
Copy link
Collaborator Author

mind-ar commented Mar 9, 2024

We just have to ensure that the cases for browsers only advertising macrolanguages (en, no, zh, etc) are handled by one of the microlanguages, and that the relevant generate functions work with this too so we don't have to manually handle this each time languages are added (it will become a nightmare to manage pretty quickly).

Done

Regarding caching, we can use the ETag / If-None-Match process to ensure the request is only processed when the values change. If we do this when/if we add logic to handle fs changes (i.e. locales added) then we can determine there is an update to be sent to clients. Though this can be added later too.

Done (etag)

Feel free to ask to do any change

@mind-ar mind-ar requested a review from nightah March 17, 2024 19:35
@mind-ar
Copy link
Collaborator Author

mind-ar commented Mar 17, 2024

Hi! @james-d-elliott and @nightah here's a functional version with custom locales support.
I think i messed it with custom locale support, i added this with the idea of allowing using embedded and custom locales at the same time, but maybe it's better to allow only embedded or only custom (using assetOverride middleware)

I'll let this as draft for now, I still need to do a general review/refactor and write some tests
Do not hesitate to request any modifications

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants