2024-09-23 01:19:11 +08:00
|
|
|
#!/bin/bash
|
2024-11-18 23:12:52 +08:00
|
|
|
declare language_choice
|
2024-09-25 00:51:25 +08:00
|
|
|
echo "========$(basename $0 .sh)========"
|
2024-11-18 23:12:52 +08:00
|
|
|
echo "1. 中文"
|
|
|
|
echo "2. 英文"
|
|
|
|
read -p "请输入:" language_choice
|
2024-09-23 01:19:11 +08:00
|
|
|
if [[ -f "/usr/bin/apt-get" ]];then
|
2024-09-23 18:25:54 +08:00
|
|
|
apt-get update -y
|
|
|
|
apt-get install -y locales
|
|
|
|
apt-get install -y language-pack-zh-hans
|
2024-09-23 01:19:11 +08:00
|
|
|
elif [[ -f "/usr/bin/apt" ]];then
|
2024-09-23 18:25:54 +08:00
|
|
|
apt update -y
|
|
|
|
apt install -y locales
|
|
|
|
apt install -y language-pack-zh-hans
|
2024-09-23 01:19:11 +08:00
|
|
|
else
|
|
|
|
echo "暂不支持该系统一键更换语言"
|
|
|
|
exit
|
|
|
|
fi
|
2024-09-26 19:46:58 +08:00
|
|
|
echo "正在更新配置文件"
|
2024-09-23 18:25:54 +08:00
|
|
|
sed -i '/^#/! s/^/# /' /etc/locale.gen
|
2024-09-23 01:19:11 +08:00
|
|
|
if ! grep LC_ALL /etc/default/locale &> /dev/null; then
|
|
|
|
echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale
|
|
|
|
fi
|
2024-11-18 23:12:52 +08:00
|
|
|
case $language_choice in
|
2024-09-23 01:19:11 +08:00
|
|
|
'1')
|
2024-09-23 18:25:54 +08:00
|
|
|
sed -i 's/.*zh_CN.UTF-8.*/zh_CN.UTF-8 UTF-8/g' /etc/locale.gen
|
|
|
|
sed -i "s/^LANG.*/LANG=zh_CN.UTF-8/g" /etc/default/locale
|
|
|
|
sed -i "s/^LC_ALL.*/LC_ALL=zh_CN.UTF-8/g" /etc/default/locale
|
2024-09-23 01:19:11 +08:00
|
|
|
;;
|
|
|
|
'2')
|
2024-09-23 18:25:54 +08:00
|
|
|
sed -i 's/.*en_US.UTF-8.*/en_US.UTF-8 UTF-8/g' /etc/locale.gen
|
|
|
|
sed -i "s/^LANG.*/LANG=en_US.UTF-8/g" /etc/default/locale
|
|
|
|
sed -i "s/^LC_ALL.*/LC_ALL=en_US.UTF-8/g" /etc/default/locale
|
2024-09-23 01:19:11 +08:00
|
|
|
;;
|
|
|
|
esac
|
2024-09-23 18:25:54 +08:00
|
|
|
locale-gen
|
2024-09-23 01:19:11 +08:00
|
|
|
update-locale
|
|
|
|
source /etc/default/locale
|
|
|
|
echo "语言更换成功"
|