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(site): the official website temporarily blocks English #2199

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Sep 27, 2024

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • The application language is now fixed to Chinese (zh-CN), overriding previous settings.
    • Routes have been updated to reflect the static Chinese language setting, removing language flexibility.
  • Bug Fixes

    • Disabled the English language option, ensuring the app defaults to Chinese regardless of URL conditions.
  • Documentation

    • Language selection features have been temporarily disabled, with plans for potential reactivation in the future.

Copy link

coderabbitai bot commented Sep 27, 2024

Walkthrough

The changes across multiple files involve a shift to a fixed language setting, specifically to Chinese (zh-CN). The variable $local._lang is now directly set to 'zhCN', while appData.lang is also hardcoded to ZH_CN_LANG. Additionally, route definitions have been modified to remove dynamic language parameters, and language selection features have been commented out in the style settings. Overall, the application will consistently use Chinese as the default language, eliminating support for English and other languages.

Changes

Files Change Summary
examples/sites/src/i18n/index.js $local._lang is now directly set to 'zhCN', overriding any previous value.
examples/sites/src/main.js appData.lang is hardcoded to ZH_CN_LANG, removing the conditional assignment based on the URL.
examples/sites/src/router.js Route paths are modified to use a static language parameter zh-CN, removing the dynamic :lang parameter.
examples/sites/src/tools/appData.js The logic to update appData.lang based on the name parameter is commented out, setting it instead to ZH_CN_LANG.
examples/sites/src/tools/useStyleSettings.js The language selection feature in getStyleSettings is disabled, indicating it may be re-enabled later after English adaptation of the official website.

Poem

🐇 In a world of code, where languages play,
A rabbit hops in, to brighten the day.
With Chinese now set, the paths are all clear,
No more English whispers, just joy and good cheer!
Let's celebrate changes, both bold and bright,
As we code through the day and dance through the night! 🌟


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 the enhancement New feature or request (功能增强) label Sep 27, 2024
Copy link

[e2e-test-warn]
The component to be tested is missing.

The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug".

Please make sure you've read our contributing guide

Copy link

@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: 2

🧹 Outside diff range and nitpick comments (2)
examples/sites/src/router.js (1)

Inconsistent Language Handling Detected Across the Codebase

The analysis reveals that while router.js has been updated to hardcode the language in route definitions, several other parts of the application still implement dynamic language handling. This inconsistency can lead to unpredictable behavior and conflicts within the application.

  • Dynamic Language Variables and Imports:

    • main.js and appData.js continue to utilize dynamic language variables such as LANG_KEY, LANG_PATH_MAP, and ZH_CN_LANG.
  • Dynamic Language Routing in Components:

    • Various Vue components in the React site still handle language dynamically, as evidenced by the presence of :language props and related functions.
  • Language-Related Functions and Methods:

    • Multiple components contain functions like getLangData and changeLang that manage language dynamically.

Recommended Actions:

  1. Unified Language Handling:

    • Refactor the remaining dynamic language implementations to align with the hardcoded approach in router.js.
  2. Comprehensive Codebase Review:

    • Conduct a thorough review of all components, services, and utilities to identify and update any instances of dynamic language routing or selection.
  3. Global Configuration:

    • Implement a centralized configuration for language settings to ensure consistency and simplify future maintenance.
🔗 Analysis chain

Line range hint 1-48: Ensure consistent language handling throughout the application

While the changes to the route definitions implement the desired language restriction, there are potential inconsistencies and areas that require attention:

  1. The redirect logic (lines 28-35) still uses dynamic language selection, which may conflict with the new hardcoded routes.
  2. Other parts of the application may expect dynamic language routing, potentially leading to unexpected behavior.

To ensure a more robust implementation of the language restriction:

  1. Review and update the redirect logic to align with the new language restriction.
  2. Conduct a thorough review of the entire application to identify and update any components, services, or utilities that rely on dynamic language routing.
  3. Consider implementing a global configuration for language restriction that can be easily toggled and applied consistently across the application.

To help identify potential issues, you can run the following script to search for language-related code that might need updating:

This script will help identify areas of the codebase that might need to be updated to ensure consistent language handling.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for language-related code that might need updating

# Search for language-related variables and imports
echo "Searching for language-related variables and imports:"
rg --type js "LANG_KEY|LANG_PATH_MAP|ZH_CN_LANG" -g '!router.js'

# Search for dynamic language routing or selection
echo "\nSearching for dynamic language routing or selection:"
rg --type js ":lang|\\$local\\[LANG_KEY\\]|LANG_PATH_MAP\\[lang\\]" -g '!router.js'

# Search for language-related functions or methods
echo "\nSearching for language-related functions or methods:"
rg --type js "function.*Lang|method.*Lang|setLang|getLang" -g '!router.js'

Length of output: 2525


Script:

#!/bin/bash
# Description: Search for language-related code that might need updating

# Search for language-related variables and imports
echo "Searching for language-related variables and imports:"
rg --type js "LANG_KEY|LANG_PATH_MAP|ZH_CN_LANG" -g '!router.js'

# Search for dynamic language routing or selection
echo "\nSearching for dynamic language routing or selection:"
rg --type js ':lang|\$local\[LANG_KEY\]|LANG_PATH_MAP\[lang\]' -g '!router.js'

# Search for language-related functions or methods
echo "\nSearching for language-related functions or methods:"
rg --type js "function.*Lang|method.*Lang|setLang|getLang" -g '!router.js'

Length of output: 2666

examples/sites/src/main.js (1)

Line range hint 1-71: Consider the broader implications of restricting language access

While the implementation achieves the goal of temporarily blocking the English version of the website, it's important to consider the broader implications:

  1. User Experience: This change might significantly impact non-Chinese speaking users. Consider adding a clear message or redirect for these users.

  2. SEO: Removing the English version might affect your website's search engine rankings for English queries. Ensure this aligns with your SEO strategy.

  3. Internationalization: This change effectively disables the i18n setup. Ensure that this doesn't cause unexpected behavior in other parts of the application that might rely on language switching.

  4. Maintenance: As this is a temporary measure, ensure that there's a plan and timeline for reverting this change. Document this plan for future reference.

Consider implementing a more robust language control system that allows for easy enabling/disabling of languages without code changes. This could involve:

  1. A configuration file or environment variable to control available languages.
  2. A feature flag system for more granular control over language availability.
  3. Server-side logic to handle language restrictions, which would allow for more dynamic control and easier updates.

These approaches would make it easier to manage language availability in the future without requiring code changes.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9a6114e and 3d899d6.

📒 Files selected for processing (5)
  • examples/sites/src/i18n/index.js (1 hunks)
  • examples/sites/src/main.js (1 hunks)
  • examples/sites/src/router.js (1 hunks)
  • examples/sites/src/tools/appData.js (1 hunks)
  • examples/sites/src/tools/useStyleSettings.js (1 hunks)
🔇 Additional comments (4)
examples/sites/src/i18n/index.js (1)

8-9: ⚠️ Potential issue

Consider a more flexible approach for language restriction

The current implementation directly sets the language to Chinese ('zhCN') by commenting out the previous logic and hardcoding the value. While this achieves the goal of blocking English, it introduces several concerns:

  1. It removes support for all non-Chinese languages, which might be more restrictive than intended.
  2. The hardcoded approach makes it difficult to revert or modify in the future.
  3. It overrides any user preferences or system settings.

Consider the following alternatives:

  1. Implement a configuration flag to enable/disable language restrictions:
const RESTRICT_TO_CHINESE = true; // Can be easily toggled

$local._lang = RESTRICT_TO_CHINESE ? 'zhCN' : ($local._lang !== 'zhCN' && $local._lang !== 'enUS' ? 'zhCN' : $local._lang);
  1. Maintain a list of allowed languages:
const ALLOWED_LANGUAGES = ['zhCN'];

$local._lang = ALLOWED_LANGUAGES.includes($local._lang) ? $local._lang : 'zhCN';

These approaches would make the restriction more flexible and easier to manage in the future.

To ensure this change doesn't affect other parts of the codebase, please run:

This will help identify any other places where language settings might need to be adjusted.

✅ Verification successful

Language restriction implementation verified

The changes in examples/sites/src/i18n/index.js correctly set the language to Chinese ('zhCN') as intended, and no additional references to $local._lang were found that could affect this implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other occurrences of $local._lang
rg --type js '$local._lang'

Length of output: 29


Script:

#!/bin/bash
# Searching for any assignments or references to $local._lang
ast-grep --lang javascript --pattern '$local._lang = $_' .

Length of output: 248

examples/sites/src/tools/appData.js (1)

19-20: ⚠️ Potential issue

Review of language setting modification

The changes align with the PR objective of temporarily blocking access to the English version of the website. However, there are several points to consider:

  1. User Experience: While the language is now fixed to Chinese, the URL is still being updated. This might lead to confusion for users who see a language change in the URL but not in the actual content.

  2. Accessibility: This change significantly impacts non-Chinese speaking users, potentially limiting their access to the website content.

  3. Implementation Approach: The current implementation seems to be a quick fix. Consider the following suggestions:

    • Implement a more robust solution that doesn't rely on commenting out code.
    • Add clear error handling or messaging for users attempting to access non-Chinese versions.
    • Update other parts of the codebase that might depend on language switching functionality.
  4. Temporary Nature: The comment and PR description suggest this is a temporary change. Could you provide more context on:

    • The expected duration of this change?
    • The plan for reverting or properly implementing language support in the future?

To ensure this change doesn't unintentionally affect other parts of the codebase, please run the following verification:

This will help identify any inconsistencies or areas that might need additional updates to align with this change.

examples/sites/src/router.js (1)

22-22: Ensure consistent language handling across routes

This change is consistent with the modification made to the overview route, applying the same language restriction to the components route.

Please refer to the previous comment regarding the hardcoding of 'zh-CN' in the route path. The same considerations and suggestions apply here as well.

examples/sites/src/main.js (1)

51-52: ⚠️ Potential issue

Consider a more maintainable approach for language restriction

The current implementation effectively blocks access to the English version of the website by hardcoding the language to Chinese. While this achieves the PR objective, there are some concerns:

  1. This change removes multi-language support entirely, which might negatively impact non-Chinese speaking users.
  2. The implementation method (commenting out code and hardcoding a value) is not ideal for maintainability, especially if this is a temporary measure.

Consider the following suggestions:

  1. Instead of commenting out the code, implement a configuration flag to enable/disable language switching. This would make it easier to revert the change in the future:
const ENABLE_LANGUAGE_SWITCHING = false; // Can be easily toggled

if (notMatchLang) {
  appData.lang = ENABLE_LANGUAGE_SWITCHING && isEnUs ? EN_US_LANG : ZH_CN_LANG;
  i18n.global.locale = appData.lang;
}
  1. Add a clear TODO comment explaining the reason for this change and when it should be reverted:
// TODO: Language switching is temporarily disabled as per PR #2199. 
// This should be re-enabled once [condition/date].
  1. Consider adding a user-friendly message for non-Chinese speaking users, explaining that the English version is temporarily unavailable.

To ensure this change doesn't break any existing functionality, please run the following verification:

This will help identify any parts of the codebase that might need to be updated to be consistent with this change.

Comment on lines +4 to +20
/** 官网英文适配后放开 */
// {
// // 语言选择
// name: 'localeMode',
// defaultValue: 'zhCN',
// title: i18nByKey('localeType'),
// options: [
// {
// value: 'zhCN',
// text: i18nByKey('zh-cn')
// },
// {
// value: 'enUS',
// text: i18nByKey('en-us')
// }
// ]
// },
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Verify and update all language-related configurations to ensure consistency with the temporary removal of the English version

The search identified numerous language and internationalization settings throughout the codebase. To fully implement the temporary restriction of the English version, please ensure that all language-related configurations are appropriately updated or commented out. This will prevent any unintended access to English content in other parts of the application.

  • Action Items:
    • Review and update all identified files to align with the temporary removal.
    • Ensure that language switches and locale settings are consistently disabled or adjusted as needed.
🔗 Analysis chain

Temporary removal of language selection aligns with PR objectives

The commented-out code block effectively implements the PR's goal of temporarily blocking the English version of the website. This change ensures that only the Chinese version is available, as intended.

While this achieves the desired outcome, please consider the following points:

  1. User Impact: This change will affect non-Chinese speaking users who may have previously relied on the English version. Ensure that there's clear communication about this temporary change on the website.

  2. Tracking Re-enablement: To prevent this temporary change from becoming permanent unintentionally, consider creating a tracking issue or TODO item for re-enabling the language selection feature once the English adaptation is complete.

  3. Code Cleanliness: While leaving commented code is generally discouraged, the explanatory comment on line 4 justifies its presence. However, ensure that this code is revisited and either removed or uncommented when the English version is ready.

To ensure this change is consistently applied across the codebase, let's verify if there are any other language-related settings or switches that might need similar treatment:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for other language-related code that might need adjustment

# Test: Look for language-related variables or settings
echo "Searching for language-related code:"
rg --type js -i '(language|locale|lang|i18n)' --glob '!**/node_modules/**'

Length of output: 211946

@@ -12,14 +12,14 @@ const context = import.meta.env.VITE_CONTEXT
let routes = [
// 组件总览
{
path: `${context}:all?/:lang/:theme/overview`,
path: `${context}:all?/zh-CN/:theme/overview`,
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider a more flexible approach for language routing

The hardcoding of 'zh-CN' in the route path aligns with the PR objective of temporarily blocking the English version. However, this approach may have some drawbacks:

  1. It removes the ability to access the overview page in languages other than Chinese.
  2. It may make it difficult to revert or add support for other languages in the future.

Consider using a configuration variable or environment flag to control the language restriction. This would allow for easier management and future flexibility. For example:

const RESTRICT_LANG = process.env.RESTRICT_LANG || 'zh-CN';

// In the route definition
path: `${context}:all?/${RESTRICT_LANG}/:theme/overview`,

This approach would make it easier to lift the language restriction or add support for other languages in the future without modifying the router code.

@kagol kagol merged commit 41f9ca8 into dev Sep 27, 2024
8 of 10 checks passed
@kagol kagol deleted the zh-to-site-0927 branch November 4, 2024 03:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request (功能增强)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants