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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/sites/src/i18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import zh from './zh.json'
import en from './en.json'

const messages = { enUS: en, zhCN: zh }
$local._lang = $local._lang !== 'zhCN' && $local._lang !== 'enUS' ? 'zhCN' : $local._lang
// $local._lang = $local._lang !== 'zhCN' && $local._lang !== 'enUS' ? 'zhCN' : $local._lang
$local._lang = 'zhCN'
const customCreateI18n = ({ locale, messages }) =>
createI18n({
locale, // set locale
Expand Down
3 changes: 2 additions & 1 deletion examples/sites/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const isZhCn = location.href.includes(`/${zhPath}`)
const isEnUs = location.href.includes(`/${enPath}`)
const notMatchLang = (isZhCn && appData.lang !== ZH_CN_LANG) || (isEnUs && appData.lang !== EN_US_LANG)
if (notMatchLang) {
appData.lang = isEnUs ? EN_US_LANG : ZH_CN_LANG
// appData.lang = isEnUs ? EN_US_LANG : ZH_CN_LANG 官网先屏蔽英文内容
appData.lang = isEnUs ? ZH_CN_LANG : ZH_CN_LANG
i18n.global.locale = appData.lang
}

Expand Down
4 changes: 2 additions & 2 deletions examples/sites/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

component: Layout,
name: 'overview',
children: [{ name: 'Overview', path: '', component: Overview, meta: { title: '组件总览 | TinyVue' } }]
},
// 组件
{
path: `${context}:all?/:lang/:theme/components/:cmpId`,
path: `${context}:all?/zh-CN/:theme/components/:cmpId`,
component: Layout,
name: 'components',
children: [{ name: 'Components', path: '', component: Components }]
Expand Down
3 changes: 2 additions & 1 deletion examples/sites/src/tools/appData.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const appFn = {
if (name !== appData.lang) {
let url = location.href
url = location.href.replace(LANG_PATH_MAP[appData.lang], LANG_PATH_MAP[name])
appData.lang = name
// appData.lang = name 官网先屏蔽英文内容
appData.lang = ZH_CN_LANG
location.replace(url)
}
},
Expand Down
33 changes: 17 additions & 16 deletions examples/sites/src/tools/useStyleSettings.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
/** 文档显示风格设置 */
const getStyleSettings = (i18nByKey) => {
const styleSettings = [
{
// 语言选择
name: 'localeMode',
defaultValue: 'zhCN',
title: i18nByKey('localeType'),
options: [
{
value: 'zhCN',
text: i18nByKey('zh-cn')
},
{
value: 'enUS',
text: i18nByKey('en-us')
}
]
},
/** 官网英文适配后放开 */
// {
// // 语言选择
// name: 'localeMode',
// defaultValue: 'zhCN',
// title: i18nByKey('localeType'),
// options: [
// {
// value: 'zhCN',
// text: i18nByKey('zh-cn')
// },
// {
// value: 'enUS',
// text: i18nByKey('en-us')
// }
// ]
// },
Comment on lines +4 to +20
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

{
// 示例代码风格
name: 'apiMode',
Expand Down
Loading