打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
桌面应用|Translate Shell :一款在 Linux 命令行中使用谷歌翻译的工具

我对 CLI 应用非常感兴趣,因此热衷于使用并分享 CLI 应用。 我之所以更喜欢 CLI 很大原因是因为我在大多数的时候都使用的是字符界面(black screen),已经习惯了使用 CLI 应用而不是 GUI 应用。

我写过很多关于 CLI 应用的文章。 最近我发现了一些谷歌的 CLI 工具,像 “Google Translator”、“Google Calendar” 和 “Google Contacts”。 这里,我想在给大家分享一下。

今天我们要介绍的是 “Google Translator” 工具。 由于我的母语是泰米尔语,我在一天内用了很多次才理解了它的意义。

谷歌翻译为其它语系的人们所广泛使用。

什么是 Translate Shell

Translate Shell (之前叫做 Google Translate CLI) 是一款借助谷歌翻译(默认)、必应翻译、Yandex.Translate 以及 Apertium 来翻译的命令行翻译器。它让你可以在终端访问这些翻译引擎。 Translate Shell 在大多数 Linux 发行版中都能使用。

如何安装 Translate Shell

有三种方法安装 Translate Shell。

  • 下载自包含的可执行文件
  • 手工安装
  • 通过包管理器安装

方法 1 : 下载自包含的可执行文件

下载自包含的可执行文件放到 /usr/bin 目录中。

  1. $ wget git.io/trans
  2. $ chmod +x ./trans
  3. $ sudo mv trans /usr/bin/

方法 2 : 手工安装

克隆 Translate Shell 的 GitHub 仓库然后手工编译。

  1. $ git clone https://github.com/soimort/translate-shell && cd translate-shell
  2. $ make
  3. $ sudo make install

方法 3 : 通过包管理器

有些发行版的官方仓库中包含了 Translate Shell,可以通过包管理器来安装。

对于 Debian/Ubuntu, 使用 APT-GET 命令 或者 APT 命令来安装。

  1. $ sudo apt-get install translate-shell

对于 Fedora, 使用 DNF 命令 来安装。

  1. $ sudo dnf install translate-shell

对于基于 Arch Linux 的系统, 使用 Yaourt 命令Packer 明快 来从 AUR 仓库中安装。

  1. $ yaourt -S translate-shell
  2. or
  3. $ packer -S translate-shell

如何使用 Translate Shell

安装好后,打开终端闭关输入下面命令。 谷歌翻译会自动探测源文本是哪种语言,并且在默认情况下将之翻译成你的 locale 所对应的语言。

  1. $ trans [Words]

下面我将泰米尔语中的单词 “நன்றி” (Nanri) 翻译成英语。 这个单词的意思是感谢别人。

  1. $ trans நன்றி
  2. நன்றி
  3. (Naṉṟi)
  4. Thanks
  5. Definitions of நன்றி
  6. [ தமிழ் -> English ]
  7. noun
  8. gratitude
  9. நன்றி
  10. thanks
  11. நன்றி
  12. நன்றி
  13. Thanks

使用下面命令也能将英语翻译成泰米尔语。

  1. $ trans :ta thanks
  2. thanks
  3. /THaNGks/
  4. நன்றி
  5. (Naṉṟi)
  6. Definitions of thanks
  7. [ English -> தமிழ் ]
  8. noun
  9. நன்றி
  10. gratitude, thanks
  11. thanks
  12. நன்றி

要将一个单词翻译到多个语种可以使用下面命令(本例中,我将单词翻译成泰米尔语以及印地语)。

  1. $ trans :ta+hi thanks
  2. thanks
  3. /THaNGks/
  4. நன்றி
  5. (Naṉṟi)
  6. Definitions of thanks
  7. [ English -> தமிழ் ]
  8. noun
  9. நன்றி
  10. gratitude, thanks
  11. thanks
  12. நன்றி
  13. thanks
  14. /THaNGks/
  15. धन्यवाद
  16. (dhanyavaad)
  17. Definitions of thanks
  18. [ English -> हिन्दी ]
  19. noun
  20. धन्यवाद
  21. thanks, thank, gratitude, thankfulness, felicitation
  22. thanks
  23. धन्यवाद, शुक्रिया

使用下面命令可以将多个单词当成一个参数(句子)来进行翻译。(只需要把句子应用起来作为一个参数就行了)。

  1. $ trans :ta 'what is going on your life?'
  2. what is going on your life?
  3. உங்கள் வாழ்க்கையில் என்ன நடக்கிறது?
  4. (Uka vāḻkkaiyil eṉṉa naakkiatu?)
  5. Translations of what is going on your life?
  6. [ English -> தமிழ் ]
  7. what is going on your life?
  8. உங்கள் வாழ்க்கையில் என்ன நடக்கிறது?

下面命令单独地翻译各个单词。

  1. $ trans :ta curios happy
  2. curios
  3. ஆர்வம்
  4. rvam)
  5. Translations of curios
  6. [ Română -> தமிழ் ]
  7. curios
  8. ஆர்வம், அறிவாளிகள், ஆர்வமுள்ள, அறிய, ஆர்வமாக
  9. happy
  10. hapē/
  11. சந்தோஷமாக
  12. (Cantōṣamāka)
  13. Definitions of happy
  14. [ English -> தமிழ் ]
  15. மகிழ்ச்சியான
  16. happy, convivial, debonair, gay
  17. திருப்தி உடைய
  18. happy
  19. adjective
  20. இன்பமான
  21. happy
  22. happy
  23. சந்தோஷமாக, மகிழ்ச்சி, இனிய, சந்தோஷமா

简洁模式:默认情况下,Translate Shell 尽可能多的显示翻译信息。如果你希望只显示简要信息,只需要加上 -b选项。

  1. $ trans -b :ta thanks
  2. நன்றி

字典模式:加上 -d 可以把 Translate Shell 当成字典来用。

  1. $ trans -d :en thanks
  2. thanks
  3. /THaNGks/
  4. Synonyms
  5. noun
  6. - gratitude, appreciation, acknowledgment, recognition, credit
  7. exclamation
  8. - thank you, many thanks, thanks very much, thanks a lot, thank you kindly, much obliged, much appreciated, bless you, thanks a million
  9. Examples
  10. - In short, thanks for everything that makes this city great this Thanksgiving.
  11. - many thanks
  12. - There were no thanks in the letter from him, just complaints and accusations.
  13. - It is a joyful celebration in which Bolivians give thanks for their freedom as a nation.
  14. - festivals were held to give thanks for the harvest
  15. - The collection, as usual, received a great response and thanks is extended to all who subscribed.
  16. - It would be easy to dwell on the animals that Tasmania has lost, but I prefer to give thanks for what remains.
  17. - thanks for being so helpful
  18. - It came back on about half an hour earlier than predicted, so I suppose I can give thanks for that.
  19. - Many thanks for the reply but as much as I tried to follow your advice, it's been a bad week.
  20. - To them and to those who have supported the office I extend my grateful thanks .
  21. - We can give thanks and words of appreciation to others for their kind deeds done to us.
  22. - Adam, thanks for taking time out of your very busy schedule to be with us tonight.
  23. - a letter of thanks
  24. - Thank you very much for wanting to go on reading, and thanks for your understanding.
  25. - Gerry has received a letter of thanks from the charity for his part in helping to raise this much needed cash.
  26. - So thanks for your reply to that guy who seemed to have a chip on his shoulder about it.
  27. - Suzanne, thanks for being so supportive with your comments on my blog.
  28. - She has never once acknowledged my thanks , or existence for that matter.
  29. - My grateful thanks go to the funders who made it possible for me to travel.
  30. - festivals were held to give thanks for the harvest
  31. - All you secretaries who made it this far into the article… thanks for your patience.
  32. - So, even though I don't think the photos are that good, thanks for the compliments!
  33. - And thanks for warning us that your secret service requires a motorcade of more than 35 cars.
  34. - Many thanks for your advice, which as you can see, I have passed on to our readers.
  35. - Tom Ryan was given a bottle of wine as a thanks for his active involvement in the twinning project.
  36. - Mr Hill insists he has received no recent complaints and has even been sent a letter of thanks from the forum.
  37. - Hundreds turned out to pay tribute to a beloved former headteacher at a memorial service to give thanks for her life.
  38. - Again, thanks for a well written and much deserved tribute to our good friend George.
  39. - I appreciate your doing so, and thanks also for the compliments about the photos!
  40. See also
  41. Thanks!, thank, many thanks, thanks to, thanks to you, special thanks, give thanks, thousand thanks, Many thanks!, render thanks, heartfelt thanks, thanks to this

使用下面格式可以使用 Translate Shell 来翻译文件。

  1. $ trans :ta file:///home/magi/gtrans.txt
  2. உங்கள் வாழ்க்கையில் என்ன நடக்கிறது?

下面命令可以让 Translate Shell 进入交互模式。 在进入交互模式之前你需要明确指定源语言和目标语言。本例中,我将英文单词翻译成泰米尔语。

  1. $ trans -shell en:ta thanks
  2. Translate Shell
  3. (:q to quit)
  4. thanks
  5. /THaNGks/
  6. நன்றி
  7. (Naṉṟi)
  8. Definitions of thanks
  9. [ English -> தமிழ் ]
  10. noun
  11. நன்றி
  12. gratitude, thanks
  13. thanks
  14. நன்றி

想知道语言代码,可以执行下面命令。

  1. $ trans -R

或者

  1. $ trans -T
  2. ┌───────────────────┬────────────────────┬────────────────────┐
  3. Afrikaans - af Hindi - hi Punjabi - pa
  4. Albanian - sq Hmong - hmn Querétaro Otomi- otq
  5. Amharic - am Hmong Daw - mww Romanian - ro
  6. Arabic - ar Hungarian - hu Russian - ru
  7. Armenian - hy Icelandic - is Samoan - sm
  8. Azerbaijani - az Igbo - ig Scots Gaelic - gd
  9. Basque - eu Indonesian - id Serbian (Cyr...-sr-Cyrl
  10. Belarusian - be Irish - ga Serbian (Latin)-sr-Latn
  11. Bengali - bn Italian - it Sesotho - st
  12. Bosnian - bs Japanese - ja Shona - sn
  13. Bulgarian - bg Javanese - jv Sindhi - sd
  14. Cantonese - yue Kannada - kn Sinhala - si
  15. Catalan - ca Kazakh - kk Slovak - sk
  16. Cebuano - ceb Khmer - km Slovenian - sl
  17. Chichewa - ny Klingon - tlh Somali - so
  18. Chinese Simp...- zh-CN Klingon (pIqaD)tlh-Qaak Spanish - es
  19. Chinese Trad...- zh-TW Korean - ko Sundanese - su
  20. Corsican - co Kurdish - ku Swahili - sw
  21. Croatian - hr Kyrgyz - ky Swedish - sv
  22. Czech - cs Lao - lo Tahitian - ty
  23. Danish - da Latin - la Tajik - tg
  24. Dutch - nl Latvian - lv Tamil - ta
  25. English - en Lithuanian - lt Tatar - tt
  26. Esperanto - eo Luxembourgish - lb Telugu - te
  27. Estonian - et Macedonian - mk Thai - th
  28. Fijian - fj Malagasy - mg Tongan - to
  29. Filipino - tl Malay - ms Turkish - tr
  30. Finnish - fi Malayalam - ml Udmurt - udm
  31. French - fr Maltese - mt Ukrainian - uk
  32. Frisian - fy Maori - mi Urdu - ur
  33. Galician - gl Marathi - mr Uzbek - uz
  34. Georgian - ka Mongolian - mn Vietnamese - vi
  35. German - de Myanmar - my Welsh - cy
  36. Greek - el Nepali - ne Xhosa - xh
  37. Gujarati - gu Norwegian - no Yiddish - yi
  38. Haitian Creole - ht Pashto - ps Yoruba - yo
  39. Hausa - ha Persian - fa Yucatec Maya - yua
  40. Hawaiian - haw Polish - pl Zulu - zu
  41. Hebrew - he Portuguese - pt
  42. └───────────────────┴────────────────────┴────────────────────┘

想了解更多选项的内容,可以查看其 man 手册。

  1. $ man trans

via: https://www.2daygeek.com/translate-shell-a-tool-to-use-google-translate-from-command-line-in-linux/

作者:Magesh Maruthamuthu 译者:lujun9972 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出  

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
"谢谢你"的几种说法
除了Thank you,还有哪些句子可以表达感激?
除了thank you,还有哪些表示感谢的表达方式
日常英语:Gratitude的几种表达法 (感恩节系列) ZT
单词 | 这样说“感谢”,会显得英文比较厉害!
秒记: gratitude
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服