这是indexloc提供的服务,不要输入任何密码
Skip to content

feat: add language switcher #1337

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

Merged
merged 2 commits into from
Sep 11, 2024
Merged

feat: add language switcher #1337

merged 2 commits into from
Sep 11, 2024

Conversation

dguyen
Copy link
Collaborator

@dguyen dguyen commented Sep 10, 2024

Description

Web changes:

  • Enabled i18n for web
  • Add option to change language in command menu
  • Add option to change language in menu-switcher

Web and marketing changes:

  • Stop setting 'en' preference into cookie if the user's language is not supported
  • Dropped middleware changes
  • Rotated cookie from 'i18n' to 'language'

Summary by CodeRabbit

  • New Features

    • Introduced a language switcher in the footer for improved language selection.
    • Added dynamic language change functionality in the command menu.
    • Implemented a dropdown menu item for quick access to the language switcher.
  • Bug Fixes

    • Resolved issues related to language change notifications and state management.
  • Translations

    • Added new translation entries for improved language support, including "Search languages..." in English and German.
    • Updated existing translations to enhance clarity and accuracy.
  • Chores

    • Simplified internationalization handling in middleware.

Copy link

vercel bot commented Sep 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
prd-app 🔄 Building (Inspect) Visit Preview 💬 Add feedback Sep 10, 2024 3:24am
prd-docs 🛑 Canceled (Inspect) Sep 10, 2024 3:24am
prd-marketing 🔄 Building (Inspect) Visit Preview 💬 Add feedback Sep 10, 2024 3:24am
stg-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 10, 2024 3:24am
stg-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 10, 2024 3:24am
stg-marketing 🛑 Canceled (Inspect) Sep 10, 2024 3:24am

Copy link
Contributor

coderabbitai bot commented Sep 10, 2024

Walkthrough

The changes introduced in this pull request enhance the internationalization features across various components of the application. Key modifications include the addition of language selection functionality in the Footer, CommandMenu, and MenuSwitcher components. The middleware has been simplified by removing locale extraction logic, while constants related to internationalization have been updated. Additionally, new translation entries have been added or modified in multiple language files, reflecting updates in user interface text.

Changes

Files Change Summary
apps/marketing/src/components/(marketing)/footer.tsx Enhanced Footer component with language switcher functionality using state management.
apps/web/src/components/(dashboard)/common/command-menu.tsx Introduced LanguageCommands for dynamic language changes in CommandMenu.
apps/web/src/components/(dashboard)/layout/menu-switcher.tsx Added language switching feature in MenuSwitcher with a new dialog for language selection.
apps/web/src/middleware.ts Removed locale extraction and cookie setting from middleware, simplifying response handling.
packages/lib/constants/app.ts Updated IS_APP_WEB_I18N_ENABLED constant from false to true, enabling web internationalization.
packages/lib/server-only/i18n/switch-i18n-language.ts Changed cookie key from 'i18n' to 'language' in switchI18NLanguage function.
packages/lib/translations/de/common.po Added German translation for "Search languages...".
packages/lib/translations/de/marketing.po Marked German translation for "Search languages..." as obsolete.
packages/lib/translations/de/web.po Updated translations and added new entries related to language features.
packages/lib/translations/en/common.po Added English translation for "Search languages...".
packages/lib/translations/en/marketing.po Commented out English translation for "Search languages...", marking it as obsolete.
packages/lib/translations/en/web.po Adjusted line numbers and added new entries for language features.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Footer
    participant CommandMenu
    participant MenuSwitcher
    participant LanguageSwitcherDialog

    User->>Footer: Clicks language button
    Footer->>LanguageSwitcherDialog: Opens dialog
    LanguageSwitcherDialog->>User: Displays language options
    User->>LanguageSwitcherDialog: Selects language
    LanguageSwitcherDialog->>Footer: Closes dialog
    Footer->>CommandMenu: Updates language
    CommandMenu->>User: Displays updated language
Loading

🐇 In the land of code where rabbits play,
New languages hop in, brightening the day.
With buttons to click and menus so grand,
Switching our tongues is now at hand!
Let's celebrate change, with joy we decree,
A multilingual world, as happy as can be! 🌍✨


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ad135b7 and 93e333a.

Files selected for processing (14)
  • apps/marketing/src/components/(marketing)/footer.tsx (4 hunks)
  • apps/web/src/components/(dashboard)/common/command-menu.tsx (6 hunks)
  • apps/web/src/components/(dashboard)/layout/menu-switcher.tsx (5 hunks)
  • apps/web/src/middleware.ts (2 hunks)
  • packages/lib/constants/app.ts (1 hunks)
  • packages/lib/server-only/i18n/switch-i18n-language.ts (1 hunks)
  • packages/lib/translations/de/common.po (1 hunks)
  • packages/lib/translations/de/marketing.po (1 hunks)
  • packages/lib/translations/de/web.po (28 hunks)
  • packages/lib/translations/en/common.po (1 hunks)
  • packages/lib/translations/en/marketing.po (1 hunks)
  • packages/lib/translations/en/web.po (28 hunks)
  • packages/lib/utils/i18n.ts (1 hunks)
  • packages/ui/components/common/language-switcher-dialog.tsx (1 hunks)
Files skipped from review due to trivial changes (5)
  • apps/web/src/middleware.ts
  • packages/lib/translations/de/common.po
  • packages/lib/translations/de/marketing.po
  • packages/lib/translations/en/common.po
  • packages/lib/translations/en/marketing.po
Additional comments not posted (16)
packages/lib/server-only/i18n/switch-i18n-language.ts (1)

7-7: LGTM!

The change in the cookie key from 'i18n' to 'language' is a semantic update that better reflects the purpose of the stored value. It does not introduce any functional issues.

packages/lib/constants/app.ts (1)

13-13: LGTM, but verify the impact.

The change to enable internationalization features for the web application by setting IS_APP_WEB_I18N_ENABLED to true is approved.

However, this change may affect the control flow where this constant is utilized. Ensure that the application behaves as expected with this change.

Run the following script to verify the usage of IS_APP_WEB_I18N_ENABLED:

packages/lib/utils/i18n.ts (1)

39-39: Verify the impact of the breaking change in the cookie key.

The cookie key used to retrieve the preferred locale has been changed from 'i18n' to 'language'. This is a breaking change.

Ensure that this change is thoroughly tested to confirm that it behaves as expected and does not break any existing functionality that relies on the 'i18n' cookie.

Run the following script to verify the cookie usage:

Verification successful

Verification Successful: No Impact on Other Parts of the Codebase

The change in the cookie key from 'i18n' to 'language' is localized to the i18n utility functions. There are no occurrences of the 'i18n' cookie elsewhere, and the 'language' cookie is used only within the expected utility functions. This indicates that the change does not break existing functionality outside these functions.

  • The 'i18n' cookie is not used elsewhere in the codebase.
  • The 'language' cookie is used appropriately within the i18n utility functions.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the 'i18n' and 'language' cookies.

# Test 1: Search for the usage of the 'i18n' cookie. Expect: No occurrences.
rg --type typescript $'\'i18n\''

# Test 2: Search for the usage of the 'language' cookie. Expect: Only occurrences in the i18n utility functions.
rg --type typescript $'\'language\'' -g '!packages/lib/utils/i18n.ts'

Length of output: 182


Script:

#!/bin/bash
# Description: Verify the usage of the 'i18n' and 'language' cookies.

# Test 1: Search for the usage of the 'i18n' cookie. Expect: No occurrences.
rg -t typescript $'\'i18n\''

# Test 2: Search for the usage of the 'language' cookie. Expect: Only occurrences in the i18n utility functions.
rg -t typescript $'\'language\'' -g '!packages/lib/utils/i18n.ts'

Length of output: 174


Script:

#!/bin/bash
# Description: Verify the usage of the 'i18n' and 'language' cookies.

# Find all TypeScript files and search for the usage of the 'i18n' cookie. Expect: No occurrences.
fd --extension ts --exec rg $'\'i18n\''

# Find all TypeScript files and search for the usage of the 'language' cookie. Expect: Only occurrences in the i18n utility functions.
fd --extension ts --exec rg $'\'language\'' -g '!packages/lib/utils/i18n.ts'

Length of output: 225

apps/marketing/src/components/(marketing)/footer.tsx (1)

47-49: LGTM!

The changes to the Footer component to add language switching functionality are approved.

Also applies to: 102-109, 117-117

apps/web/src/components/(dashboard)/common/command-menu.tsx (2)

215-217: LGTM!

The changes to the CommandMenu component to add a new command item for changing the language are approved.

Also applies to: 231-231


283-324: LGTM!

The new LanguageCommands component is approved.

apps/web/src/components/(dashboard)/layout/menu-switcher.tsx (4)

3-4: LGTM!

The code changes are approved.


22-22: LGTM!

The code changes are approved.


47-48: LGTM!

The code changes are approved.


Line range hint 282-301: LGTM!

The code changes are approved.

packages/lib/translations/en/web.po (6)

301-303: LGTM!

The new translation entry for "Admin panel" looks good.


309-311: LGTM!

The new translation entry for "All documents" looks good.


325-327: LGTM!

The new translation entry for "All templates" looks good.


Line range hint 479-515: LGTM!

The line number change for "An unknown error occurred" looks good. It's likely a result of reorganizing the entries.


1776-1779: LGTM!

The new translation entry for "Language" looks good.


3537-3540: LGTM!

The new translation entry for "Unable to change the language at this time. Please try again later." looks good.


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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

Copy link

github-actions bot commented Sep 10, 2024

Thank you for following the naming conventions for pull request titles! 💚🚀

@github-actions github-actions bot added apps: web Issues related to the webapp apps: marketing Issues related to website or marketing app labels Sep 10, 2024
@Mythie
Copy link
Collaborator

Mythie commented Sep 10, 2024

ready when you are

@dguyen dguyen marked this pull request as ready for review September 11, 2024 02:57
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.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (2)
packages/ui/components/common/language-switcher-dialog.tsx (1)

1-57: LGTM, but consider improving accessibility.

The LanguageSwitcherDialog component is well-structured and correctly handles language switching and cookie updates. The usage of the CommandDialog primitive and SUPPORTED_LANGUAGES constant is appropriate.

However, the component can be further improved by adding accessibility attributes and keyboard navigation support.

Consider applying the following changes to improve accessibility:

 <CommandDialog open={open} onOpenChange={setOpen}>
-  <CommandInput placeholder={_(msg`Search languages...`)} />
+  <CommandInput 
+    placeholder={_(msg`Search languages...`)}
+    aria-label={_(msg`Search languages`)}
+  />
   
   <CommandList>
     <CommandGroup>
       {Object.values(SUPPORTED_LANGUAGES).map((language) => (
         <CommandItem
           key={language.short}
           value={language.full}
           onSelect={async () => setLanguage(language.short)}
+          aria-label={_(msg`Select language: ${language.full}`)}
         >
           <CheckIcon
             className={cn(
               'mr-2 h-4 w-4',
               i18n.locale === language.short ? 'opacity-100' : 'opacity-0',
             )}
+            aria-label={_(msg`Selected`)}
           />
           {SUPPORTED_LANGUAGES[language.short].full}
         </CommandItem>
       ))}
     </CommandGroup>
   </CommandList>
 </CommandDialog>

These changes add appropriate ARIA labels to improve screen reader support and provide better context for keyboard navigation.

packages/lib/translations/de/web.po (1)

Line range hint 1-1: TODO: Add tests

The TODO comment indicates that tests are missing for this module. Having unit tests is important to ensure code correctness and prevent regressions.

Do you need any help with setting up a testing framework or writing the unit tests? I'd be happy to assist or provide some examples. Just let me know!

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ad135b7 and 93e333a.

Files selected for processing (14)
  • apps/marketing/src/components/(marketing)/footer.tsx (4 hunks)
  • apps/web/src/components/(dashboard)/common/command-menu.tsx (6 hunks)
  • apps/web/src/components/(dashboard)/layout/menu-switcher.tsx (5 hunks)
  • apps/web/src/middleware.ts (2 hunks)
  • packages/lib/constants/app.ts (1 hunks)
  • packages/lib/server-only/i18n/switch-i18n-language.ts (1 hunks)
  • packages/lib/translations/de/common.po (1 hunks)
  • packages/lib/translations/de/marketing.po (1 hunks)
  • packages/lib/translations/de/web.po (28 hunks)
  • packages/lib/translations/en/common.po (1 hunks)
  • packages/lib/translations/en/marketing.po (1 hunks)
  • packages/lib/translations/en/web.po (28 hunks)
  • packages/lib/utils/i18n.ts (1 hunks)
  • packages/ui/components/common/language-switcher-dialog.tsx (1 hunks)
Files skipped from review due to trivial changes (5)
  • apps/web/src/middleware.ts
  • packages/lib/translations/de/common.po
  • packages/lib/translations/de/marketing.po
  • packages/lib/translations/en/common.po
  • packages/lib/translations/en/marketing.po
Additional comments not posted (16)
packages/lib/server-only/i18n/switch-i18n-language.ts (1)

7-7: LGTM!

The change in the cookie key from 'i18n' to 'language' is a semantic update that better reflects the purpose of the stored value. It does not introduce any functional issues.

packages/lib/constants/app.ts (1)

13-13: LGTM, but verify the impact.

The change to enable internationalization features for the web application by setting IS_APP_WEB_I18N_ENABLED to true is approved.

However, this change may affect the control flow where this constant is utilized. Ensure that the application behaves as expected with this change.

Run the following script to verify the usage of IS_APP_WEB_I18N_ENABLED:

packages/lib/utils/i18n.ts (1)

39-39: Verify the impact of the breaking change in the cookie key.

The cookie key used to retrieve the preferred locale has been changed from 'i18n' to 'language'. This is a breaking change.

Ensure that this change is thoroughly tested to confirm that it behaves as expected and does not break any existing functionality that relies on the 'i18n' cookie.

Run the following script to verify the cookie usage:

Verification successful

Verification Successful: No Impact on Other Parts of the Codebase

The change in the cookie key from 'i18n' to 'language' is localized to the i18n utility functions. There are no occurrences of the 'i18n' cookie elsewhere, and the 'language' cookie is used only within the expected utility functions. This indicates that the change does not break existing functionality outside these functions.

  • The 'i18n' cookie is not used elsewhere in the codebase.
  • The 'language' cookie is used appropriately within the i18n utility functions.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the 'i18n' and 'language' cookies.

# Test 1: Search for the usage of the 'i18n' cookie. Expect: No occurrences.
rg --type typescript $'\'i18n\''

# Test 2: Search for the usage of the 'language' cookie. Expect: Only occurrences in the i18n utility functions.
rg --type typescript $'\'language\'' -g '!packages/lib/utils/i18n.ts'

Length of output: 182


Script:

#!/bin/bash
# Description: Verify the usage of the 'i18n' and 'language' cookies.

# Test 1: Search for the usage of the 'i18n' cookie. Expect: No occurrences.
rg -t typescript $'\'i18n\''

# Test 2: Search for the usage of the 'language' cookie. Expect: Only occurrences in the i18n utility functions.
rg -t typescript $'\'language\'' -g '!packages/lib/utils/i18n.ts'

Length of output: 174


Script:

#!/bin/bash
# Description: Verify the usage of the 'i18n' and 'language' cookies.

# Find all TypeScript files and search for the usage of the 'i18n' cookie. Expect: No occurrences.
fd --extension ts --exec rg $'\'i18n\''

# Find all TypeScript files and search for the usage of the 'language' cookie. Expect: Only occurrences in the i18n utility functions.
fd --extension ts --exec rg $'\'language\'' -g '!packages/lib/utils/i18n.ts'

Length of output: 225

apps/marketing/src/components/(marketing)/footer.tsx (1)

47-49: LGTM!

The changes to the Footer component to add language switching functionality are approved.

Also applies to: 102-109, 117-117

apps/web/src/components/(dashboard)/common/command-menu.tsx (2)

215-217: LGTM!

The changes to the CommandMenu component to add a new command item for changing the language are approved.

Also applies to: 231-231


283-324: LGTM!

The new LanguageCommands component is approved.

apps/web/src/components/(dashboard)/layout/menu-switcher.tsx (4)

3-4: LGTM!

The code changes are approved.


22-22: LGTM!

The code changes are approved.


47-48: LGTM!

The code changes are approved.


Line range hint 282-301: LGTM!

The code changes are approved.

packages/lib/translations/en/web.po (6)

301-303: LGTM!

The new translation entry for "Admin panel" looks good.


309-311: LGTM!

The new translation entry for "All documents" looks good.


325-327: LGTM!

The new translation entry for "All templates" looks good.


Line range hint 479-515: LGTM!

The line number change for "An unknown error occurred" looks good. It's likely a result of reorganizing the entries.


1776-1779: LGTM!

The new translation entry for "Language" looks good.


3537-3540: LGTM!

The new translation entry for "Unable to change the language at this time. Please try again later." looks good.

@dguyen dguyen merged commit 357bdd3 into main Sep 11, 2024
10 checks passed
@dguyen dguyen deleted the feat/web-lang-switcher branch September 11, 2024 03:22
This was referenced Sep 19, 2024
@coderabbitai coderabbitai bot mentioned this pull request Oct 19, 2024
This was referenced Nov 6, 2024
This was referenced Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apps: marketing Issues related to website or marketing app apps: web Issues related to the webapp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants