Ubuntu翻译任何选中的文字
1 問(wèn)題
Google Chrome瀏覽器可以集成Google Translator插件,實(shí)現(xiàn)瀏覽器頁(yè)面文字的翻譯,但是除了瀏覽器,PDF、LibreOffice等軟件上面的文字也經(jīng)常需要翻譯。
Ubuntu上可以使用有道詞典,但是兼容性不太好,這里說(shuō)明另外一種方法
2 安裝
運(yùn)行以下命令,安裝所需軟件:
$ sudo apt-get update $ sudo apt-get install libnotify-bin wget xsel- libnotify-bin: 用于發(fā)送desktop notifications
- wget: 調(diào)用Google Translator接口,獲取翻譯結(jié)果
- xsel: 獲取當(dāng)前highlighted的text
3 腳本
在$PATH下創(chuàng)建名為notitrans的腳本,賦予執(zhí)行權(quán)限chmod +x notitrans,內(nèi)容如下:
#!/usr/bin/env bash notify-send --icon=info "$(xsel -o)" "$(wget -U "Mozilla/5.0" -qO - "http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=zh&dt=t&q=$(xsel -o | sed "s/[\"'<>]//g")" | sed "s/,,,0]],,.*//g" | awk -F'"' '{print $2, $6}')"該腳本主要做了以下幾件事:
上述tl=zh指明翻譯的目標(biāo)語(yǔ)言是中文,其他的有en for English,ru for Russian,fr for french
4 快捷鍵
設(shè)置一個(gè)快捷鍵shortcut,運(yùn)行notitrans命令,達(dá)到按快捷鍵就翻譯的效果
如下路徑設(shè)置:
System Settings > Keyboard > Shortcuts > Custom Shortcuts最終的效果圖如下:
5 參考
http://www.webupd8.org/2016/03/translate-any-text-you-select-on-your.html
https://www.faqforge.com/linux/distributions/ubuntu/create-custom-keyboard-shortcut-ubuntu-16-04/
http://forum.ubuntu.com.cn/viewtopic.php?f=21&t=296308
總結(jié)
以上是生活随笔為你收集整理的Ubuntu翻译任何选中的文字的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 苹果cms v10用户搜索什么就入库添加
- 下一篇: 三重视角看陈彤:一个网媒老兵的谢幕