Debian Strings国际化设置主要涉及系统语言、软件包翻译等,核心步骤如下:
sudo apt update sudo apt install locales sudo dpkg-reconfigure locales zh_CN.UTF-8),确保勾选LC_ALL、LANG等环境变量。locale 输出需显示目标语言(如LANG=zh_CN.UTF-8)。xgettext --keyword=_ --output=messages.pot *.c (_为默认翻译函数标记,需在代码中使用)。mkdir -p zh_CN/LC_MESSAGES msginit --input=messages.pot --locale=zh_CN --output=zh_CN/LC_MESSAGES/messages.po messages.po,将msgstr替换为目标语言文本(如"Hello"→"你好")。msgfmt zh_CN/LC_MESSAGES/messages.po -o zh_CN/LC_MESSAGES/messages.mo .mo文件放置于软件包的/usr/share/locale/zh_CN/LC_MESSAGES/目录。通过设置环境变量临时切换(如切换为英文):
export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8 生效需重启终端或应用程序。
gettext函数加载翻译。参考来源: