安裝中文語言包
sudo apt install language-pack-zh-hans
配置中文顯示
首先運行如下命令配置 locale?
$ sudo vi /etc/locale.gen
找到 *zh_CN.UTF-8 UTF-8*?并取消注釋,然后保存并退出。
locale.gen...
# zh_CN.GBK GBK
zh_CN.UTF-8 UTF-8
# zh_HK BIG5-HKSCS
此處省略200行 ...
?運行命令 sudo locale-gen 進行編譯
$ sudo locale-gen
Generating locales (this might take a while)...
en_US.UTF-8... done
zh_CN.UTF-8... done
zh_SG.UTF-8... done
Generation complete.
設置默認語言是中文
編輯文件?/etc/default/locale
$ sudo vi /etc/default/locale
將文件內(nèi)容更改如下,重啟 wsl 生效。
1 LANG=zh_CN.UTF-8
2 LANGUAGE="zh_CN:zh:en_US:en"
安裝輸入法框架
有中文語言包后就可以正式準備安裝輸入法了。Linux 中安裝其它語言的輸入法首先需要安裝輸入法框架,之后再安裝輸入法。常用的輸入法框架有 ibus 和 fcitx,本文只介紹 fcitx5 框架的安裝。
- Fcitx
Fcitx?(Flexible Input Method Framework) ──即小企鵝輸入法,它是一個以 GPL 方式發(fā)布的輸入法平臺,可以通過安裝引擎支持多種輸入法,支持簡入繁出,是在 Linux 操作系統(tǒng)中常用的中文輸入法。它的優(yōu)點是,短小精悍、跟程序的兼容性比較好。
- Fcitx5
Fcitx5 是繼?Fcitx?后的新一代輸入法框架。
若在系統(tǒng)已經(jīng)存在一個輸入法框架的情況下安裝其它框架可能會無法正常工作,需要刪除不需要的框架和輸入法,可使用如下方式刪除:
# 刪除軟件包保留軟件的配置文件
sudo apt remove xxxx
# 刪除軟件包和軟件的配置文件?
sudo apt purge xxxx?
# 清理卸載對象的關(guān)聯(lián)文件
sudo apt autoremove
安裝fcitx5框架
使用 Fcitx 5 輸入法框架需要安裝三部分基本內(nèi)容:
?1. 安裝主程序包
sudo apt install fcitx5
fcitx5包?僅提供基本框架,且僅支持英文。如果要輸入其他語言(例如中文或日文),則需要安裝x相應的輸入法引擎(IME)
2. 輸入法引擎
# 安裝中文輸入法引擎
sudo apt install fcitx5-chinese-addons
fcitx5-chinese-addons 包含與中文相關(guān)的 addon,例如拼音、雙拼和五筆等。
3. 環(huán)境依賴包?
sudo apt install fcitx5-frontend-gtk4 fcitx5-frontend-gtk3 fcitx5-frontend-gtk2 fcitx5-frontend-qt5 fcitx5-config-qt
完整fcitx5安裝包
運行上面的安裝命令后fcitx5框架可能并未安裝完整,若想完整安裝需要打開語言支持按照提示進行后續(xù)安裝。如果使用圖形桌面xfce4無法打開語言支持或報錯可參考內(nèi)容:
WSL(ubuntu2204)使用xfce4桌面打不開語言支持及配置WSL服務自啟https://blog.csdn.net/w47_csdn/article/details/129101896
如果圖形桌面xfce4中可以正常打開語言支持但并不提示"完整安裝",可嘗試在終端中以管理員身份執(zhí)行命令來打開:
$ sudo /usr/bin/gnome-language-selector
若想查找所有的fcitx5相關(guān)安裝包可運行命令:apt-cache search fcitx5 查看。
$ apt-cache search fcitx5
fcitx5 - 下一代 Fcitx 輸入法框架
fcitx5-data - Fcitx Input Method Framework v5 (common data files)
fcitx5-frontend-gtk2 - GTK2 IM Module for fcitx5
fcitx5-frontend-gtk3 - GTK3 IM Module for fcitx5
fcitx5-frontend-gtk4 - GTK4 IM Module for fcitx5
fcitx5-frontend-qt5 - IM module for fcitx5
fcitx5-module-chttrans - Fcitx Input Method Framework v5 (chttrans module)
fcitx5-module-cloudpinyin - Fcitx Input Method Framework v5 (cloudpinyin module)
fcitx5-module-cloudpinyin-dev - Development files for fcitx5 cloudpinyin module
fcitx5-module-emoji - Fcitx Input Method Framework v5 (emoji module)
fcitx5-module-fullwidth - Fcitx Input Method Framework v5 (fullwidth module)
fcitx5-module-lua - Lua support for fcitx5
fcitx5-module-lua-common - Lua support for fcitx5 (common files)
fcitx5-module-lua-dev - Lua support for fcitx5 (development files)
fcitx5-module-pinyinhelper - Fcitx Input Method Framework v5 (pinyinhelper module)
fcitx5-module-pinyinhelper-dev - Development files for fcitx5 pinyinhelper module
fcitx5-module-punctuation - Fcitx Input Method Framework v5 (punctuation module)
fcitx5-module-punctuation-dev - Development files for fcitx5 punctuation module
fcitx5-module-quickphrase - Fcitx Input Method Framework v5 (quickphrase module)
fcitx5-module-wayland - Fcitx Input Method Framework v5 (wayland modules)
fcitx5-module-xorg - Fcitx Input Method Framework v5 (xorg modules)
fcitx5-modules - Fcitx Input Method Framework v5 (core modules)
fcitx5-modules-dev - Fcitx Input Method Framework v5 (input modules dev files)
fcitx5-mozc - Mozc engine for fcitx5 - Client of the Mozc input method
fcitx5-pinyin - Fcitx Input Method Framework v5 (builtin pinyin support)
fcitx5-rime - Rime input method support for fcitx5
fcitx5-table - Fcitx Input Method Framework v5 (builtin table support)
fcitx5-table-amharic - Flexible Input Method Framework v5 - Amharic table
fcitx5-table-arabic - Flexible Input Method Framework v5 - Arabic table
fcitx5-table-cns11643 - Flexible Input Method Framework v5 - Cns11643 table
fcitx5-table-compose - Flexible Input Method Framework v5 - Compose table
fcitx5-table-emoji - Flexible Input Method Framework v5 - Emoji table
fcitx5-table-ipa-x-sampa - Flexible Input Method Framework v5 - IPA-X-SAMPA table
fcitx5-table-latex - Flexible Input Method Framework v5 - LaTeX table
fcitx5-table-malayalam-phonetic - Flexible Input Method Framework v5 - Malayalam phonetic table
fcitx5-table-other - Additional table based input method for Fcitx 5
fcitx5-table-rustrad - Flexible Input Method Framework v5 - Rustrad table
fcitx5-table-tamil-remington - Flexible Input Method Framework v5 - Tamil Remington table
fcitx5-table-thai - Flexible Input Method Framework v5 - Thai table
fcitx5-table-translit - Flexible Input Method Framework v5 - Translit table
fcitx5-table-translit-ua - Flexible Input Method Framework v5 - Ukrainian Translit table
fcitx5-table-viqr - Flexible Input Method Framework v5 - Viqr table
fcitx5-table-yawerty - Flexible Input Method Framework v5 - Yawerty table
gir1.2-fcitxg-1.0 - GObject introspection data for fcitx5
libfcitx5-qt-data - Qt library and IM module for fcitx5 (data files)
libfcitx5-qt-dev - Qt library and IM module for fcitx5 (development files)
libfcitx5-qt1 - Qt library and IM module for fcitx5
libfcitx5config-dev - Fcitx Input Method Framework v5 (config library dev files)
libfcitx5config6 - Fcitx Input Method Framework v5 (config library)
libfcitx5core-dev - Fcitx Input Method Framework v5 (core library dev files)
libfcitx5core7 - Fcitx Input Method Framework v5 (core library)
libfcitx5gclient-dev - GLib-based D-Bus client library for fcitx5 (development files)
libfcitx5gclient2 - GLib-based D-Bus client library for fcitx5 (library)
libfcitx5utils-dev - Fcitx Input Method Framework v5 (utils library dev files)
libfcitx5utils2 - Fcitx Input Method Framework v5 (utils library)
fcitx5-anthy - Fcitx5 wrapper for Anthy IM engine
fcitx5-chewing - Chewing input method support for fcitx5
fcitx5-chinese-addons - Chinese-related addon for fcitx5 (metapackage)
fcitx5-chinese-addons-bin - Chinese-related addon for fcitx5 (binary tools)
fcitx5-chinese-addons-data - Chinese-related addon for fcitx5 (shared data files)
fcitx5-config-qt - configuration tool for Fcitx5 (Qt version)
fcitx5-hangul - Hangul input method wrapper for fcitx5
fcitx5-keyman - Fcitx5 wrapper for Keyman keyboarding platform
fcitx5-kkc - Fcitx5 wrapper for libkkc IM engine
fcitx5-libthai - Thai input method engine for Fcitx5 based on LibThai
fcitx5-m17n - m17n support module for Fcitx5 Input Method Framework
fcitx5-material-color - UI theme for fcitx5 following Material Design
fcitx5-sayura - Fcitx5 wrapper for Sayura IM engine
fcitx5-skk - Japanese SKK input engine for Fcitx5
fcitx5-unikey - Vietnamese Input Method Engine for Fcitx5 using Unikey Engine
kde-config-fcitx5 - KDE configuration module for Fcitx5
libime-bin - Generic Input Method Implementation (tools)
libime-data - Generic Input Method Implementation library (data files)
libime-data-language-model - Generic Input Method Implementation library (language model)
libimecore-dev - Generic Input Method Implementation (core dev files)
libimecore0 - Generic Input Method Implementation (core library)
libimepinyin-dev - Generic Input Method Implementation (pinyin dev files)
libimepinyin0 - Generic Input Method Implementation (pinyin library)
libimetable-dev - Generic Input Method Implementation (table dev files)
libimetable0 - Generic Input Method Implementation (table library)
安裝中文詞庫
對于 Fcitx5 的中文輸入法, 目前在倉庫里提供了數(shù)個詞庫:
fcitx5-pinyin-zhwiki包:felixonmars?根據(jù)中文維基百科創(chuàng)建的適用于拼音輸入法的詞庫
fcitx5-pinyin-sougou:適用于拼音輸入法的搜狗詞庫
rime-pinyin-zhwiki包:適用于 Rime 輸入法的詞庫
fcitx5-pinyin-moegirl-rimeAUR:適用于 Rime 輸入法的詞庫
cedict:從 cedict辭典 導出的詞庫。
moegirl:outloudvi?根據(jù)萌娘百科創(chuàng)建的詞庫
注意: 手動下載的詞典文件直接放到 ~/.local/share/fcitx5/pinyin/dictionaries 路徑下即可。詞典文件的后綴名應當為 .dict
以維基百科詞庫為例,在 GitHub 打開?維基百科中文拼音詞庫?的?Releases?界面,下載最新版的?.dict
?文件。按照 README 的指導,將其復制到?~/.local/share/fcitx5/pinyin/dictionaries/ 文件夾下即可。
# 下載詞庫文件
wget https://github.com/felixonmars/fcitx5-pinyin-zhwiki/releases/download/0.2.4/zhwiki-20220416.dict
# 創(chuàng)建存儲目錄
mkdir ~/.local/share/fcitx5/pinyin/dictionaries/
# 移動詞庫文件至該目錄
mv zhwiki-20220416.dict ~/.local/share/fcitx5/pinyin/dictionaries/
設置為默認輸入法
使用 im-config 工具可以配置首選輸入法,在任意命令行輸入:
$ im-config
根據(jù)彈出窗口的提示,將首選輸入法設置為 Fcitx 5 即可。?
關(guān)于 linux 環(huán)境變量
使用?
$HOME/.pam_environment
?設置環(huán)境變量的用戶注意啦!由于?CVE-2010-4708, pam 上游在 1.4.0 版本中設置了默認不讀取用戶的環(huán)境變量設置,需要用戶自行更換環(huán)境變量設置位置或恢復原默認讀取行為。--- 依云’s?Blog
使用 X11 的桌面環(huán)境,通常通過 display manager 來登錄,比如 lightdm 和 sddm。這倆都支持?
~/.xprofile
。這個文件會在啟動過程中被 source,使用的 shell 是由 dm 自己確定的。lightdm 和 sddm 都是用的?/bin/sh
(分別位于?/etc/lightdm/Xsession
?和?/usr/share/sddm/scripts/Xsession
?文件里)。可以看到,除了讀取?.xprofile
?外,lightdm 也會讀取?.profile
。sddm 甚至連 bash、zsh、tcsh、fish 的啟動配置腳本都給讀了。--- 依云’s?Blog
Linux 的環(huán)境變量怎么設置 - 依云's Bloghttps://blog.lilydjwg.me/2020/7/22/linux-environment-variables.215496.html
linux中環(huán)境變量及環(huán)境變量配置文件詳解 - kelelipenghttps://www.cnblogs.com/kelelipeng/p/13638185.html
配置fcitx5環(huán)境變量
為X11桌面會話設置環(huán)境變量,即將以下配置項寫入某一配置文件中
export XMODIFIERS=@im=fcitx
export QT_IM_MODULE=fcitx
export GTK_IM_MODULE=fcitx
這步環(huán)境變量配置非常重要,即使前面的安裝步驟完美,如果在這步配置有問題亦將無法在xfce4桌面切換出中文輸入法。查找了許多文章的fcitx環(huán)境變量配置,大體上是下面這幾種:
# 在~/.profile文件中配置環(huán)境變量
$ vim ~/.profile
# 在~/.pam_environment文件中配置環(huán)境變量
$ vim ~/.pam_environment
# 在~/.xprofile文件中配置環(huán)境變量
$ vim ~/.xprofile
# 在/etc/environment文件中配置環(huán)境變量
$ vim /etc/environment
# 在/etc/profile文件中配置環(huán)境變量
$ vim /etc/profile
參考了上面的依云’s Blog基本可以排除 ~/.pam_environment 配置。使用?~/.profile?或?~/.xprofile 配置好多次依然不起作用,其余兩個是系統(tǒng)級的環(huán)境配置沒有試過。猜測 fcitx5 的環(huán)境變量配置可能與安裝桌面時選擇的 display manager 有關(guān),本文環(huán)境在安裝 xfce4 時在 gdm3和 lightdm 中選擇了 gdm3,按照依云’s Blog所述這個?~/.xprofile 是 ssdm 和 lightdm 會讀取的配置,而?~/.profile 只有 lightdm 才會讀取,那 gdm3 應該讀取哪個配置文件呢?最終測試其余兩個系統(tǒng)級配置都會生效。
配置開機自啟動
安裝 Fcitx5 后并沒有自動添加到開機自啟動中,每次開機后需要手動在應用程序中找到并啟動,非常繁瑣。如果是原生Ubuntu系統(tǒng),則解決方案非常簡單,在 Tweaks(sudo apt install gnome-tweaks)中將 Fcitx5 添加到「開機啟動程序」列表中即可。
但是在 WSL Ubuntu 環(huán)境下并沒有 Tweaks 應用,手動安裝 Tweaks 后在桌面可能找不到程序入口,可以在終端中使用命令 sudo /usr/bin/gnome-tweaks 打開。
這里提供一個無需安裝 Tweaks 的方法,在 xfce4 桌面中依次打開?所有應用程序->設置->會話和啟動??彈出窗口后切換到?應用程序自啟動? 點擊 "+" 添加開機啟動程序 /usr/bin/fcitx5 如圖所示:
Fcitx5 配置工具
Fcitx5 提供了一個基于 Qt 的強大易用的 GUI 配置工具,可以對輸入法功能進行配置。有多種啟動該配置工具的方法:
1. 在?所有應用程序->設置?中打開「Fcitx 配置」
2. 在 Fcitx 托盤圖標上右鍵打開「設置」
3. 使用命令運行:fcitx5-configtool
根據(jù)個人偏好進行設置即可。需要注意的是「輸入法」標簽頁下,應將「鍵盤 - 英語」放在首位,拼音(或其他中文輸入法)放在后面的位置。
診斷定位問題
當你遇到任何 Fcitx5 有關(guān)的問題,例如?Ctrl+Space 快捷鍵在有的程序中不能工作,首先應該用?
fcitx5-diagnose
?命令診斷問題原因。?fcitx5-diagnose
?會列出所有 Fcitx5 正常運行所需的前提條件,從輸出結(jié)果中通常可以找到問題的原因。---?Arch Linux WiKi
?若進行上述配置后依然無法在圖形桌面中切換中文輸入法,請使用?fcitx5-diagnose 打印日志。
?主要查看環(huán)境變量是否配置成功,如果依然提示需要配置環(huán)境變量則請嘗試更換配置文件。
下面貼上一段環(huán)境變量配置報錯的日志可供參考:?
# 前端設置:
## Xim:
1. `${XMODIFIERS}`:
**XMODIFIERS 沒有設置**
**請使用您發(fā)行版提供的工具將環(huán)境變量 XMODIFIERS 設為 "@im=fcitx" 或者將 `export XMODIFIERS=@im=fcitx` 添加到您的 `~/.xprofile` 中. 參見 [輸入法相關(guān)的環(huán)境變量: XMODIFIERS](http://fcitx-im.org/wiki/Input_method_related_environment_variables/zh-cn#XMODIFIERS).**
從環(huán)境變量中獲取的 Xim 服務名稱為 fcitx.
2. 根窗口上的 XIM_SERVERS:
Xim 服務的名稱與環(huán)境變量中設置的相同.
## Qt:
1. qt4 - `${QT4_IM_MODULE}`:
**請使用您發(fā)行版提供的工具將環(huán)境變量 QT_IM_MODULE 設為 "fcitx" 或者將 `export QT_IM_MODULE=fcitx` 添加到您的 `~/.xprofile` 中. 參見 [輸入法相關(guān)的環(huán)境變量: QT_IM_MODULE](http://fcitx-im.org/wiki/Input_method_related_environment_variables/zh-cn#QT_IM_MODULE).**
2. qt5 - `${QT_IM_MODULE}`:
**請使用您發(fā)行版提供的工具將環(huán)境變量 QT_IM_MODULE 設為 "fcitx" 或者將 `export QT_IM_MODULE=fcitx` 添加到您的 `~/.xprofile` 中. 參見 [輸入法相關(guān)的環(huán)境變量: QT_IM_MODULE](http://fcitx-im.org/wiki/Input_method_related_environment_variables/zh-cn#QT_IM_MODULE).**
3. Qt 輸入法模塊文件:
找到了未知的 fcitx qt 模塊: `/usr/lib/x86_64-linux-gnu/qt5/qml/DBus/Org/Fcitx/Fcitx/libFcitx.so`.
找到了 Qt5 的輸入法模塊: `/usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so`.
找到了 Qt4 的輸入法模塊: `/usr/lib/x86_64-linux-gnu/qt4/plugins/inputmethods/qtim-fcitx.so`.
## Gtk:
1. gtk - `${GTK_IM_MODULE}`:
**請使用您發(fā)行版提供的工具將環(huán)境變量 GTK_IM_MODULE 設為 "fcitx" 或者將 `export GTK_IM_MODULE=fcitx` 添加到您的 `~/.xprofile` 中. 參見 [輸入法相關(guān)的環(huán)境變量: GTK_IM_MODULE](http://fcitx-im.org/wiki/Input_method_related_environment_variables/zh-cn#GTK_IM_MODULE).**
?參考資料
Fcitx5 - Arch Linux 中文維基https://wiki.archlinuxcn.org/wiki/Fcitx5
Ubuntu22.04安裝Fcitx5中文輸入法(詳細) - 知乎https://zhuanlan.zhihu.com/p/508797663
關(guān)于 fcitx5 以及最近的環(huán)境變量問題 - WeepingDogelhttps://weepingdogel.github.io/posts/%E5%85%B3%E4%BA%8Efcitx5/
在Ubuntu中安裝中文輸入法_Naisu Xu的博客-CSDNhttps://blog.csdn.net/Naisu_kun/article/details/121482385
wsl ubuntu安裝中文語言和windows字體_acooler15的博客https://blog.csdn.net/acooler15/article/details/111681560文章來源:http://www.zghlxwxcb.cn/news/detail-414849.html
wsl ubuntu 安裝中文語言包并設為默認_無所事事的大T的博客https://blog.csdn.net/taurusbt/article/details/124484990文章來源地址http://www.zghlxwxcb.cn/news/detail-414849.html
到了這里,關(guān)于WSL(ubuntu2204)xfce4安裝中文環(huán)境和fcitx5框架及中文輸入法的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!