本文目录导读:

Windows (PowerShell)
# 获取当前系统区域代码 Get-WinSystemLocale | Select-Object -ExpandProperty Name # 或获取用户区域设置 Get-WinUserLanguageList | Select-Object -ExpandProperty LanguageTag # 通过注册表获取 (Get-ItemProperty "HKCU:\Control Panel\International").LocaleName
Windows (CMD/Batch)
@echo off :: 使用系统变量 echo %LANG% :: 或通过注册表 reg query "HKCU\Control Panel\International" /v LocaleName
Linux (Bash)
# 获取系统区域设置 echo $LANG # 获取所有区域相关变量 locale # 获取特定类别 locale -a | grep -i "^zh" # 显示中文区域 # 只输出区域代码 locale | grep LANG | cut -d= -f2
macOS (Bash)
# 获取当前区域 defaults read -g AppleLocale # 获取系统语言区域 echo $LANG # 获取所有区域设置 locale
Python (跨平台)
import locale
# 获取默认区域
default_locale = locale.getdefaultlocale()
print(f"区域代码: {default_locale[0]}")
print(f"编码: {default_locale[1]}")
# 获取当前区域设置
current_locale = locale.getlocale()
print(f"当前区域: {current_locale}")
# 系统区域列表
import subprocess
import sys
if sys.platform == "win32":
result = subprocess.run(["powershell", "Get-WinSystemLocale | Select-Object -ExpandProperty Name"],
capture_output=True, text=True)
print(result.stdout.strip())
else:
result = subprocess.run(["locale", "-a"], capture_output=True, text=True)
print(result.stdout)
常用区域代码示例
zh-CN 简体中文(中国)
zh-TW 繁体中文(台湾)
en-US 英语(美国)
en-GB 英语(英国)
ja-JP 日语(日本)
ko-KR 韩语(韩国)
根据你的需求选择适合的方法,PowerShell和Python方案最通用且功能全面。