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: core components support simple locale switching #4273

Merged
merged 3 commits into from
Aug 29, 2024
Merged

Conversation

anncwb
Copy link
Collaborator

@anncwb anncwb commented Aug 29, 2024

Description

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • New Features

    • Introduced a new localization composable (useSimpleLocale) for managing language settings and translations.
    • Enhanced drawer and modal components to support localized text for buttons.
  • Visual Updates

    • Updated the primary theme color for a fresher, more vibrant appearance across the application.
  • Documentation

    • Added a README for the use-simple-locale module to assist developers with internationalization implementation.
  • Bug Fixes

    • Improved the flexibility of drawer and modal components by allowing customizable button text without defaults.

@anncwb anncwb requested review from vince292007 and a team as code owners August 29, 2024 14:11
Copy link

changeset-bot bot commented Aug 29, 2024

⚠️ No Changeset found

Latest commit: 4b6aeda

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Aug 29, 2024

Warning

Rate limit exceeded

@anncwb has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 41 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 65d7267 and 4b6aeda.

Walkthrough

The changes introduce a new localization feature through the useSimpleLocale composable, enhancing internationalization support across various components. Additionally, the primary theme color is updated for a consistent visual appearance. Documentation is improved with new README files, and dependencies are added to facilitate the new functionalities.

Changes

Files Change Summary
docs/src/en/guide/in-depth/theme.md, packages/@core/base/design/src/design-tokens/default/index.css Updated --primary color variable from 211 91% 39% to 231 98% 65%.
packages/@core/composables/src/index.ts Added export for use-simple-locale composable.
packages/@core/composables/src/use-simple-locale/README.md Introduced README for use-simple-locale composable, outlining its functionality.
packages/@core/composables/src/use-simple-locale/index.ts Implemented useSimpleLocale composable for locale management with reactivity.
packages/@core/composables/src/use-simple-locale/messages.ts Defined Locale type and messages constant for translations, along with getMessages function for retrieving localized strings.
packages/@core/ui-kit/popup-ui/src/drawer/drawer-api.ts Removed default cancelText and confirmText properties from defaultState in DrawerApi.
packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue Integrated useSimpleLocale for localized cancelText and confirmText.
packages/@core/ui-kit/popup-ui/src/modal/modal-api.ts Removed cancelText and confirmText properties from defaultState in ModalApi.
packages/@core/ui-kit/popup-ui/src/modal/modal.vue Added localization support using useSimpleLocale for button texts.
packages/locales/package.json Added dependency on @vben-core/composables.
packages/locales/src/i18n.ts Integrated setSimpleLocale function for improved locale management.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant LocaleManager as Locale Manager
    participant Component as UI Component

    App->>LocaleManager: setSimpleLocale(lang)
    LocaleManager->>Component: update locale
    Component->>LocaleManager: request translation for key
    LocaleManager->>Component: return translated message
Loading

🐰 In the meadow, I hop with glee,
New colors and words, oh joy for me!
With every change, the world feels bright,
Localized texts, a pure delight!
So come, dear friends, let's sing and play,
For brighter paths on this fine day! 🌼


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.

@github-actions github-actions bot added documentation Improvements or additions to documentation feature labels Aug 29, 2024
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 (1)
packages/@core/ui-kit/popup-ui/src/modal/modal-api.ts (1)

Potential Issues with Removing cancelText and confirmText

The properties cancelText and confirmText are still used in various parts of the codebase, including drawer-api.ts, modal.ts, and their test files. Removing these properties from defaultState might lead to issues if they are expected to be part of the state elsewhere.

  • Files with Usage:
    • packages/@core/ui-kit/popup-ui/src/drawer/drawer-api.ts
    • packages/@core/ui-kit/popup-ui/src/modal/__tests__/modal-api.test.ts
    • packages/@core/ui-kit/popup-ui/src/modal/modal.ts
    • packages/@core/ui-kit/popup-ui/src/drawer/__tests__/drawer-api.test.ts

Please review these usages to ensure that the removal does not impact the functionality. Consider refactoring or updating the code where necessary.

Analysis chain

Line range hint 16-30: LGTM! But verify the usage of removed properties.

The removal of cancelText and confirmText properties simplifies the state management. However, ensure that these properties are not used elsewhere in the codebase.

The code changes are approved.

Run the following script to verify the usage of cancelText and confirmText properties:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `cancelText` and `confirmText` properties.

# Test: Search for the usage of `cancelText` and `confirmText`. Expect: No occurrences.
rg --type python -A 5 $'cancelText'
rg --type python -A 5 $'confirmText'

Length of output: 132


Script:

#!/bin/bash
# Description: Verify the usage of `cancelText` and `confirmText` properties in TypeScript files.

# Test: Search for the usage of `cancelText` and `confirmText`. Expect: No occurrences.
rg --type ts -A 5 'cancelText'
rg --type ts -A 5 'confirmText'

Length of output: 7979

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 98da067 and 65d7267.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (14)
  • docs/src/en/guide/in-depth/theme.md (2 hunks)
  • docs/src/guide/in-depth/theme.md (2 hunks)
  • packages/@core/base/design/src/design-tokens/default/index.css (1 hunks)
  • packages/@core/composables/src/index.ts (1 hunks)
  • packages/@core/composables/src/use-simple-locale/README.md (1 hunks)
  • packages/@core/composables/src/use-simple-locale/index.ts (1 hunks)
  • packages/@core/composables/src/use-simple-locale/messages.ts (1 hunks)
  • packages/@core/ui-kit/popup-ui/src/drawer/drawer-api.ts (1 hunks)
  • packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue (3 hunks)
  • packages/@core/ui-kit/popup-ui/src/modal/modal-api.ts (1 hunks)
  • packages/@core/ui-kit/popup-ui/src/modal/modal.vue (3 hunks)
  • packages/@core/ui-kit/shadcn-ui/src/components/logo/logo.vue (1 hunks)
  • packages/locales/package.json (1 hunks)
  • packages/locales/src/i18n.ts (3 hunks)
Files skipped from review due to trivial changes (3)
  • docs/src/en/guide/in-depth/theme.md
  • packages/@core/composables/src/use-simple-locale/README.md
  • packages/@core/ui-kit/shadcn-ui/src/components/logo/logo.vue
Additional comments not posted (19)
packages/@core/composables/src/index.ts (1)

5-5: LGTM!

The new export statement for use-simple-locale is correctly added and does not affect existing exports or logic.

packages/@core/composables/src/use-simple-locale/messages.ts (3)

1-1: LGTM!

The type Locale is correctly defined and provides a clear representation of supported locales.


3-12: LGTM!

The constant messages is correctly defined and provides a clear mapping of messages for each locale.


14-14: LGTM!

The function getMessages is correctly defined and provides a clear way to retrieve messages for a given locale.

packages/locales/package.json (1)

24-24: LGTM!

The new dependency @vben-core/composables is correctly added and aligns with the changes introduced in the other files.

packages/@core/composables/src/use-simple-locale/index.ts (2)

1-5: LGTM!

The import statements are necessary and correctly implemented.


7-25: LGTM!

The function useSimpleLocale is correctly implemented and follows best practices.

packages/locales/src/i18n.ts (2)

13-14: LGTM!

The import statement for useSimpleLocale is necessary and correctly implemented.


24-25: LGTM!

The function loadLocaleMessages is correctly updated to use setSimpleLocale.

Also applies to: 82-82

packages/@core/ui-kit/popup-ui/src/drawer/drawer-api.ts (1)

31-36: LGTM!

The constructor modification allows for more flexible customization of the drawer component.

packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue (3)

6-10: LGTM!

The import statement for useSimpleLocale is correct and aligns with the objective of adding localization support.


41-41: LGTM!

The usage of useSimpleLocale composable is correct and enhances the localization functionality of the component.


172-180: LGTM!

The changes in the template for cancelText and confirmText slots are correct and improve the user experience by ensuring that the component can display text in the appropriate language.

packages/@core/ui-kit/popup-ui/src/modal/modal.vue (3)

6-10: LGTM!

The import statement for useSimpleLocale is correct and aligns with the objective of adding localization support.


51-51: LGTM!

The usage of useSimpleLocale composable is correct and enhances the localization functionality of the component.


243-251: LGTM!

The changes in the template for cancelText and confirmText slots are correct and improve the user experience by ensuring that the component can display text in the appropriate language.

packages/@core/base/design/src/design-tokens/default/index.css (1)

31-31: LGTM! Verify the visual impact of the new primary theme color.

The primary theme color is updated from 211 91% 39% to 231 98% 65%. Ensure that the new color is consistent with the design guidelines and does not negatively impact the user experience.

docs/src/guide/in-depth/theme.md (2)

56-56: LGTM! Verify the visual impact of the new primary theme color.

The primary theme color is updated from 211 91% 39% to 231 98% 65%. Ensure that the new color is consistent with the design guidelines and does not negatively impact the user experience.


354-354: LGTM! Verify the visual impact of the new primary theme color.

The primary theme color is updated from 211 91% 39% to 231 98% 65%. Ensure that the new color is consistent with the design guidelines and does not negatively impact the user experience.

Copy link

sonarcloud bot commented Aug 29, 2024

@anncwb anncwb merged commit a77cc00 into main Aug 29, 2024
14 checks passed
@anncwb anncwb deleted the feature/core-i18n branch August 29, 2024 14:31
kkfive pushed a commit to kkfive/vue-vben-admin that referenced this pull request Sep 14, 2024
* feat: core components support simple locale switching

* fix: test error

* fix: test error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant