feat(scripts): add internationalization support to quickstart script#6
Conversation
Add bilingual support (English and Chinese) to the quickstart.sh script to improve accessibility for Chinese-speaking users. Changes: - Add LANG variable to control language setting (en or zh) - Implement msg() function for message localization - Add select_language() interactive language selection - Localize all user-facing messages, prompts, and help text - Add --lang CLI option to set language preference - Update usage examples to show language selection The script now defaults to English but allows users to select Chinese through an interactive prompt or via the --lang flag.
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ✏️ Tip: You can disable in-progress messages and the fortune message in your review settings. Tip You can disable sequence diagrams in the walkthrough.Disable the ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e9450ca62f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if [[ "$INTERACTIVE" = true ]] && [[ "$LANG" == "en" ]]; then | ||
| select_language |
There was a problem hiding this comment.
Skip language prompt when --lang is explicitly set
In interactive terminals, passing --lang en still triggers select_language, because the guard only checks LANG == "en" and cannot distinguish the default from an explicit CLI choice. This makes the new --lang flag non-deterministic for English users (they are prompted again and can accidentally switch languages), which contradicts the option’s documented behavior as a direct language setting.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
This PR adds internationalization support to the quickstart.sh script, enabling bilingual operation in English and Chinese. The implementation introduces a localization framework through a msg() function that returns language-specific strings based on a LANG variable, and adds an interactive language selection feature at script startup.
Changes:
- Implements a msg() localization function with 80+ message keys for all user-facing text
- Adds select_language() function for interactive language selection at script startup
- Introduces --lang CLI flag to set language preference (en or zh)
- Translates all user-facing messages, prompts, help text, and success/error messages
| if [[ "$INTERACTIVE" = true ]] && [[ "$LANG" == "en" ]]; then | ||
| select_language | ||
| fi |
There was a problem hiding this comment.
The language selection logic only triggers when LANG == "en" (the default). This means if a user explicitly sets --lang zh on the command line, and the script is in interactive mode, the select_language() prompt won't appear (which is correct). However, if the user's system has LANG environment variable set to something other than "en" (which is common), this script's LANG variable will be overridden by the system's LANG variable, and the language selection won't trigger.
This is another consequence of using the LANG variable name, which conflicts with the system environment variable. Once the variable is renamed (as suggested in the previous comment), this logic should work correctly.
| ANTHROPIC_KEY="$2"; shift 2 ;; | ||
| --openai-key) | ||
| OPENAI_KEY="$2"; shift 2 ;; | ||
| --lang) |
There was a problem hiding this comment.
The --lang argument accepts any value without validation. If a user provides an invalid language code (e.g., --lang fr or --lang invalid), the script will silently accept it and use English as the fallback in all msg() calls, which could be confusing.
Consider adding validation to ensure only "en" or "zh" are accepted, with a clear error message if an invalid value is provided. For example:
--lang)
if [[ "$2" != "en" && "$2" != "zh" ]]; then
print_error "Invalid language: $2. Supported languages: en, zh"
exit 1
fi
LANG="$2"; shift 2 ;;| --lang) | |
| --lang) | |
| if [[ "$2" != "en" && "$2" != "zh" ]]; then | |
| print_error "Invalid language: $2. Supported languages: en, zh" | |
| exit 1 | |
| fi |
|
|
||
| print_header "S3 Public Endpoint Configuration" >&2 | ||
| cat >&2 <<'EOF' | ||
| print_header "$(msg "header.s3_endpoint")" >&2 |
There was a problem hiding this comment.
The print_header function is being called with $(msg "header.s3_endpoint") wrapped in double quotes as an argument. However, command substitution with $(...) is already being used, so this will execute msg "header.s3_endpoint" and pass the result to print_header.
The issue is that this creates an extra subshell execution during command substitution. While this works, it's inefficient and inconsistent. Consider passing the message key directly and having print_header call msg(), or at minimum, remove the unnecessary double quotes around the command substitution since it's already properly quoted.
| if [[ "$LANG" == "zh" ]]; then | ||
| print_info "跳过 S3 公共端点(本地开发模式)" >&2 | ||
| else | ||
| print_info "Skipping S3 public endpoint (local development mode)" >&2 | ||
| fi |
There was a problem hiding this comment.
These hardcoded localized messages are inconsistent with the msg() function pattern used elsewhere in the script. The message "跳过 S3 公共端点(本地开发模式)" / "Skipping S3 public endpoint (local development mode)" should be defined in the msg() function and called using a message key for consistency.
This would make the code more maintainable and easier to update translations in the future. Consider adding a message key like "info.skipping_s3_endpoint" to the msg() function and using it here.
| if [[ "$LANG" == "zh" ]]; then | |
| print_info "跳过 S3 公共端点(本地开发模式)" >&2 | |
| else | |
| print_info "Skipping S3 public endpoint (local development mode)" >&2 | |
| fi | |
| print_info "$(msg "info.skipping_s3_endpoint")" >&2 |
| if [[ "$LANG" == "zh" ]]; then | ||
| echo " 如果您想使用 GPT 模型,可以稍后在 .env 中添加" | ||
| else | ||
| echo " Add it later in .env if you want to use GPT models" | ||
| fi | ||
| fi | ||
|
|
||
| echo "" | ||
| print_success "Bootstrap completed!" | ||
| print_success "$(msg "success.bootstrap")" | ||
| echo "" | ||
| echo "Next steps:" | ||
| echo " 1. Make sure ANTHROPIC_AUTH_TOKEN is set in .env" | ||
| if [[ "$START_ALL" = true ]]; then | ||
| echo " 2. Open browser: http://localhost:3000" | ||
| echo " 3. View logs: docker compose logs -f backend executor-manager frontend" | ||
| if [[ "$LANG" == "zh" ]]; then | ||
| echo "后续步骤:" | ||
| echo " 1. 确保在 .env 中设置了 ANTHROPIC_AUTH_TOKEN" | ||
| if [[ "$START_ALL" = true ]]; then | ||
| echo " 2. 打开浏览器: http://localhost:3000" | ||
| echo " 3. 查看日志: docker compose logs -f backend executor-manager frontend" | ||
| else | ||
| echo " 2. 启动服务: docker compose up -d" | ||
| echo " 3. 打开浏览器: http://localhost:3000" | ||
| fi | ||
| else | ||
| echo " 2. Start services: docker compose up -d" | ||
| echo " 3. Open browser: http://localhost:3000" | ||
| echo "Next steps:" | ||
| echo " 1. Make sure ANTHROPIC_AUTH_TOKEN is set in .env" | ||
| if [[ "$START_ALL" = true ]]; then | ||
| echo " 2. Open browser: http://localhost:3000" | ||
| echo " 3. View logs: docker compose logs -f backend executor-manager frontend" | ||
| else | ||
| echo " 2. Start services: docker compose up -d" | ||
| echo " 3. Open browser: http://localhost:3000" | ||
| fi | ||
| fi |
There was a problem hiding this comment.
These hardcoded localized messages are inconsistent with the msg() function pattern used elsewhere in the script. Messages like "如果您想使用 GPT 模型,可以稍后在 .env 中添加" / "Add it later in .env if you want to use GPT models" should be defined in the msg() function for consistency.
Similarly, the "Next steps" section (lines 996-1016) contains multiple hardcoded messages that should be centralized in the msg() function. This would improve maintainability and make it easier to update translations in the future.
| # 将空值视为"未设置" | ||
| if [[ -z "$value" ]]; then | ||
| return 1 | ||
| fi | ||
| # Treat example placeholders as "not set". | ||
| # 将示例占位符视为"未设置" |
There was a problem hiding this comment.
Code comments have been changed from English to Chinese. This is inconsistent with typical open-source project conventions where code comments are generally kept in English to ensure all contributors can understand the codebase, regardless of which languages the UI supports.
User-facing messages should be localized, but internal code comments and documentation should remain in English for maintainability and accessibility to the broader developer community.
| # 修复: 改进逻辑以允许在值不同时覆盖 | ||
| if [[ "$FORCE_ENV" = false ]]; then | ||
| local existing_value | ||
| existing_value="$(read_env_key "$key" || true)" | ||
| # Only skip if the value is EXACTLY the same as what we are trying to write | ||
| # 仅当值完全相同时才跳过 |
There was a problem hiding this comment.
Code comments have been changed from English to Chinese. This is inconsistent with typical open-source project conventions where code comments are generally kept in English to ensure all contributors can understand the codebase, regardless of which languages the UI supports.
User-facing messages should be localized, but internal code comments and documentation should remain in English for maintainability and accessibility to the broader developer community.
| # 修复: 移除了 "保留当前值? [Y/n]" 逻辑 | ||
| # 改为使用标准的默认值提示样式 | ||
|
|
||
| local display_default="" | ||
| if [[ -n "$current_value" ]]; then | ||
| # Mask the key for display | ||
| # 为显示掩码密钥 |
There was a problem hiding this comment.
Code comments have been changed from English to Chinese. This is inconsistent with typical open-source project conventions where code comments are generally kept in English to ensure all contributors can understand the codebase, regardless of which languages the UI supports.
User-facing messages should be localized, but internal code comments and documentation should remain in English for maintainability and accessibility to the broader developer community.
| -h|--help) | ||
| usage; exit 0 ;; |
There was a problem hiding this comment.
The --help flag is processed after the --lang flag in the argument parsing loop. However, the usage() function that is called by --help uses the msg() function which depends on the LANG variable. This creates a potential issue: if a user runs ./scripts/quickstart.sh --help --lang zh, the help text will be shown in English (the default) because --help exits before --lang is processed.
To fix this, the --lang argument should be processed before calling usage(), or the usage() function call should be deferred until after all arguments are parsed. Alternatively, add a note in the documentation that --lang should be specified before --help.
| # Language setting (en or zh) | ||
| LANG="en" |
There was a problem hiding this comment.
The variable name LANG conflicts with a standard environment variable used by the system for locale settings. Using LANG can cause unexpected behavior as it may override or be overridden by the system's locale configuration. This could affect how various commands (like date, sort, etc.) behave within the script.
Consider renaming this variable to something more specific like UI_LANG, SCRIPT_LANG, or POCO_LANG to avoid conflicts with the system environment variable.
| # Language setting (en or zh) | |
| LANG="en" | |
| # Script message language setting (en or zh). Do not override system $LANG. | |
| SCRIPT_LANG="${SCRIPT_LANG:-en}" |
Add bilingual support (English and Chinese) to the quickstart.sh script to improve accessibility for Chinese-speaking users.
Changes:
The script now defaults to English but allows users to select Chinese through an interactive prompt or via the --lang flag.
Summary by CodeRabbit