Skip to content

Commit 3a0ace0

Browse files
Copilotpaigeman
andauthored
Translate Chinese comments and messages to English in mise Java integration script (#26)
* Initial plan * Translate Chinese comments and messages to English Co-authored-by: paigeman <53284808+paigeman@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: paigeman <53284808+paigeman@users.noreply.github.com>
1 parent b727beb commit 3a0ace0

1 file changed

Lines changed: 57 additions & 57 deletions

File tree

mise_java_home_integration.sh

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10,141 +10,141 @@
1010
# Note: Not all distributions support this integration (e.g. liberica)
1111
# ==========================================
1212

13-
# 1. 检查 mise 是否存在
13+
# 1. Check if mise exists
1414
if ! command -v mise &> /dev/null; then
15-
echo "错误: 未找到 mise 命令,请确保已安装并添加到 PATH"
15+
echo "Error: mise command not found. Please ensure it is installed and added to PATH."
1616
exit 1
1717
fi
1818

19-
# 2. 获取当前 Mise 激活的 Java 信息
20-
# 获取当前激活的版本号 (例如: openjdk-21)
19+
# 2. Get current Mise-activated Java information
20+
# Get the currently activated version number (e.g., openjdk-21)
2121
JAVA_VERSION_NAME=$(mise current java 2>/dev/null | awk '{print $1}')
22-
# 获取该版本的绝对安装路径
22+
# Get the absolute installation path of this version
2323
JAVA_INSTALL_PATH=$(mise where java 2>/dev/null)
2424

2525
if [ -z "$JAVA_INSTALL_PATH" ]; then
26-
echo "错误: 当前目录没有激活任何 Mise Java 版本。"
27-
echo "💡 请先执行: mise use java@21 (或你想要的版本)"
26+
echo "Error: No Mise Java version is active in the current directory."
27+
echo "💡 Please run: mise use java@21 (or your desired version)"
2828
exit 1
2929
fi
3030

31-
# 额外验证:确保版本名称有效
31+
# Additional validation: ensure version name is valid
3232
if [ -z "$JAVA_VERSION_NAME" ]; then
33-
echo "错误: 无法获取 Java 版本名称。"
33+
echo "Error: Unable to retrieve Java version name."
3434
exit 1
3535
fi
3636

37-
# 3. 定义目标路径 (遵循 mise 官方文档的命名方式,不加前缀)
37+
# 3. Define target path (following mise official documentation naming convention, no prefix)
3838
TARGET_DIR="/Library/Java/JavaVirtualMachines/${JAVA_VERSION_NAME}.jdk"
3939

4040
# ==========================================
41-
# 功能函数
41+
# Function Definitions
4242
# ==========================================
4343

4444
function do_link() {
45-
echo "🔍 检测当前 Java: $JAVA_VERSION_NAME"
46-
echo "📂 源路径: $JAVA_INSTALL_PATH"
45+
echo "🔍 Detected current Java: $JAVA_VERSION_NAME"
46+
echo "📂 Source path: $JAVA_INSTALL_PATH"
4747

48-
# --- 核心检查:源 JDK 是否有 Contents 目录 ---
48+
# --- Core check: Does the source JDK have a Contents directory? ---
4949
if [ ! -d "$JAVA_INSTALL_PATH/Contents" ]; then
50-
echo "⚠️ 警告: 该 JDK 版本不包含标准的 macOS 'Contents' 目录结构。"
51-
echo "🚫 这是一个非 macOS 标准构建 (可能是 Linux 版),无法直接链接到系统。"
52-
echo "🧹 无需清理,操作已取消。"
50+
echo "⚠️ Warning: This JDK version does not contain the standard macOS 'Contents' directory structure."
51+
echo "🚫 This is a non-macOS standard build (possibly a Linux version) and cannot be directly linked to the system."
52+
echo "🧹 No cleanup needed, operation cancelled."
5353
exit 1
5454
fi
5555

56-
# 检查目标是否已存在
56+
# Check if target already exists
5757
if [ -d "$TARGET_DIR" ]; then
58-
echo "⚠️ 目标已存在: $TARGET_DIR"
58+
echo "⚠️ Target already exists: $TARGET_DIR"
5959
read -p "Overwrite? (y/n): " confirm
60-
# 使用 tr 转换为小写以兼容旧版 Bash (macOS 默认 Bash 3.2)
60+
# Use tr to convert to lowercase for compatibility with older Bash versions (macOS default Bash 3.2)
6161
if [[ $(echo "$confirm" | tr '[:upper:]' '[:lower:]') != "y" ]]; then exit 0; fi
6262

6363
if ! sudo rm -rf "$TARGET_DIR"; then
64-
echo "删除旧目录失败,请检查权限。"
64+
echo "Failed to remove old directory, please check permissions."
6565
exit 1
6666
fi
6767
fi
6868

69-
echo "🚀 开始链接..."
69+
echo "🚀 Starting link creation..."
7070

71-
# 按照官方文档方式创建目录和链接
72-
# 使用 && 确保如果 mkdir 成功但 ln 失败时能正确清理
71+
# Create directory and link following official documentation
72+
# Use && to ensure proper cleanup if mkdir succeeds but ln fails
7373
if sudo mkdir "$TARGET_DIR" && sudo ln -s "$JAVA_INSTALL_PATH/Contents" "$TARGET_DIR/Contents"; then
74-
echo "链接创建成功!"
75-
echo "🔗 映射关系: $TARGET_DIR/Contents -> $JAVA_INSTALL_PATH/Contents"
74+
echo "Link created successfully!"
75+
echo "🔗 Mapping: $TARGET_DIR/Contents -> $JAVA_INSTALL_PATH/Contents"
7676

77-
# 验证链接是否指向预期的源路径
78-
# 使用 realpath 规范化路径进行比较(处理可能的相对路径问题)
77+
# Verify that the link points to the expected source path
78+
# Use realpath to normalize paths for comparison (handles potential relative path issues)
7979
REAL_LINK_TARGET=$(realpath "$TARGET_DIR/Contents" 2>/dev/null)
8080
EXPECTED_TARGET=$(realpath "$JAVA_INSTALL_PATH/Contents" 2>/dev/null)
8181

82-
# 如果 realpath 不可用或失败,直接比较 readlink 的结果
82+
# If realpath is not available or fails, compare readlink results directly
8383
if [ -z "$REAL_LINK_TARGET" ] || [ -z "$EXPECTED_TARGET" ]; then
8484
REAL_LINK_TARGET=$(readlink "$TARGET_DIR/Contents")
8585
EXPECTED_TARGET="$JAVA_INSTALL_PATH/Contents"
8686
fi
8787

8888
if [ "$REAL_LINK_TARGET" != "$EXPECTED_TARGET" ]; then
89-
echo "链接目标不匹配!"
90-
echo " 预期: $EXPECTED_TARGET"
91-
echo " 实际: $REAL_LINK_TARGET"
92-
echo "🧹 正在执行清理工作..."
89+
echo "Link target mismatch!"
90+
echo " Expected: $EXPECTED_TARGET"
91+
echo " Actual: $REAL_LINK_TARGET"
92+
echo "🧹 Performing cleanup..."
9393
sudo rm -rf "$TARGET_DIR"
94-
echo "清理完成。"
94+
echo "Cleanup completed."
9595
exit 1
9696
fi
9797

98-
# 验证 macOS 是否真正识别到该 JDK
98+
# Verify that macOS actually recognizes this JDK
9999
echo "------------------------------------------------"
100-
echo "🔎 正在验证 macOS 是否识别此 JDK..."
101-
# 检查目标目录是否出现在 java_home 的输出中
102-
# 使用 -Fi 进行不区分大小写的固定字符串匹配
100+
echo "🔎 Verifying if macOS recognizes this JDK..."
101+
# Check if the target directory appears in java_home output
102+
# Use -Fi for case-insensitive fixed string matching
103103
if /usr/libexec/java_home -V 2>&1 | grep -Fiq "${JAVA_VERSION_NAME}.jdk"; then
104-
echo "✅ macOS 已成功识别该 JDK"
104+
echo "✅ macOS has successfully recognized this JDK!"
105105
echo "------------------------------------------------"
106106
echo ""
107-
echo "💡 使用以下命令查看所有可用的 Java 版本:"
107+
echo "💡 Use the following command to view all available Java versions:"
108108
echo " /usr/libexec/java_home -V"
109109
else
110-
echo "⚠️ macOS 未能识别此 JDK"
110+
echo "⚠️ macOS could not recognize this JDK."
111111
echo ""
112-
echo "📚 这通常意味着该发行版不支持与 macOS 系统集成。"
113-
echo "💡 常见不支持的发行版包括: liberica"
112+
echo "📚 This usually means the distribution does not support macOS system integration."
113+
echo "💡 Common unsupported distributions include: liberica, etc."
114114
echo ""
115115
read -p "Keep the link anyway and continue? (y/n): " keep_link
116-
# 使用 tr 转换为小写以兼容旧版 Bash (macOS 默认 Bash 3.2)
116+
# Use tr to convert to lowercase for compatibility with older Bash versions (macOS default Bash 3.2)
117117
if [[ $(echo "$keep_link" | tr '[:upper:]' '[:lower:]') != "y" ]]; then
118-
echo "🧹 正在执行清理工作..."
118+
echo "🧹 Performing cleanup..."
119119
sudo rm -rf "$TARGET_DIR"
120-
echo "清理完成。"
120+
echo "Cleanup completed."
121121
exit 1
122122
fi
123123
fi
124124
echo "------------------------------------------------"
125125
else
126-
echo "链接命令执行失败!"
127-
echo "🧹 正在执行清理工作 (删除空目录)..."
126+
echo "Link command execution failed!"
127+
echo "🧹 Performing cleanup (removing empty directory)..."
128128
sudo rm -rf "$TARGET_DIR"
129-
echo "清理完成。"
129+
echo "Cleanup completed."
130130
exit 1
131131
fi
132132
}
133133

134134
function do_unlink() {
135-
echo "🗑 准备移除系统映射: $TARGET_DIR"
135+
echo "🗑 Preparing to remove system mapping: $TARGET_DIR"
136136

137137
if [ ! -d "$TARGET_DIR" ]; then
138-
echo "⚠️ 该路径不存在,可能未链接过: $TARGET_DIR"
138+
echo "⚠️ This path does not exist, may not have been linked: $TARGET_DIR"
139139
exit 0
140140
fi
141141

142142
sudo rm -rf "$TARGET_DIR"
143-
echo "已移除链接。原 Mise 文件保留,仅断开系统集成。"
143+
echo "Link removed. Original Mise files retained, only system integration disconnected."
144144
}
145145

146146
# ==========================================
147-
# 主逻辑
147+
# Main Logic
148148
# ==========================================
149149

150150
ACTION=$1
@@ -157,12 +157,12 @@ case "$ACTION" in
157157
do_unlink
158158
;;
159159
*)
160-
echo "用法: $0 [link | unlink]"
160+
echo "Usage: $0 [link | unlink]"
161161
echo ""
162-
echo " link : 将当前 Mise Java 链接到 macOS 系统目录"
163-
echo " unlink : 取消当前 Mise Java 的系统链接"
162+
echo " link : Link current Mise Java to macOS system directory"
163+
echo " unlink : Unlink current Mise Java from system"
164164
echo ""
165-
echo "当前检测到的版本: $JAVA_VERSION_NAME"
165+
echo "Currently detected version: $JAVA_VERSION_NAME"
166166
exit 1
167167
;;
168168
esac

0 commit comments

Comments
 (0)