SkillAgentSearch skills...

Fanyi

Translate Words or Sentences via Online Translators

Install / Use

/learn @YuLab-SMU/Fanyi
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

fanyi: Translate Words or Sentences via Online Translators

<!-- README.md is generated from README.Rmd. Please edit that file -->

Useful functions to translate text for multiple languages using online translators. For example, by translating error messages and descriptive analysis results into a language familiar to the user, it enables a better understanding of the information, thereby reducing the barriers caused by language. It offers several helper functions to query gene information to help interpretation of interested genes (e.g., marker genes, differential expression genes), and provides utilities to translate ‘ggplot’ graphics. This package is not affiliated with any of the online translators. The developers do not take responsibility for the invoice it incurs when using this package, especially for exceeding the free quota.

To cite fanyi in publications use:

:writing_hand: Authors

Guangchuang YU

School of Basic Medical Sciences, Southern Medical University

https://yulab-smu.top

:arrow_double_down: Installation

Get the released version from CRAN:

install.packages("fanyi")

Or the development version from github:

## install.packages("yulab.utils")
yulab.utils::install_zip_gh("YuLab-SMU/fanyi")

:beginner: Usages

To switch between different online translators:

You should use set_translate_source() to set the default translator used in translate().

Alternatively, you can call specific functions to use a specific translator (e.g., baidu_translate(), bing_translate(), youdao_translate(), etc.).

To use baidu translate:

  1. go to https://fanyi-api.baidu.com/manage/developer and register as an individual developer
  2. enable 通用文本翻译API service
  3. get appid and key (密钥)
  4. set appid and key with source = "baidu" using set_translate_option()
  5. have fun with baidu_translate()

To use bing translate:

  1. register a free Azure account
  2. enable Azure AI services | Translator from https://portal.azure.com/
  3. create a translation service with free tier pricing version (you need a visa/master card to complete registration and will not be charged until you exceed 2 million characters monthly)
  4. get your key and region
  5. set key and region with source = "bing" using set_translate_option()
  6. have fun with bing_translate()

To use youdao (有道智云) translate:

  1. go to https://ai.youdao.com/ and register an account
  2. click 自然语言翻译服务 and create an app from subsection 文本翻译
  3. get your 应用ID as appid, and 应用秘钥 as key
  4. set appid and key with source = "youdao" using set_translate_option()
  5. have fun with youdao_translate()
  6. (bonus) you can also create 术语表 (dictionary for the terms) as a user-defined dictionary and get the dict id to help you get precise translation in a certain domain.

To use volcengine (火山引擎) translate:

  1. go to https://www.volcengine.com/ and register an account
  2. enable Machine Translation (机器翻译)
  3. get app key
    • click 控制台
    • click your avatar at the upper-right corner
    • select API访问密钥
    • click 新建密钥
  4. for security concerns, you are highly advised to add a sub-account (新建子用户)
  5. click the subaccount name in 身份管理 - 用户, and click permissions (权限)
  6. in Global permissions (全局权限), add the following permissions: “TranslateFullAccess”, “I18nTranslateFullAccess”
  7. set appid and key with source = "volcengine" using set_translate_option() and have fun with volcengine_translate()

To use caiyun (彩云小译) translate:

  1. go to https://platform.caiyunapp.com/login and register
  2. login with your account, create a translation app (创建应用) choose 翻译 as 接口类型
  3. get the token, set it as the key with source = "caiyun" using set_translate_option()
  4. have fun with caiyun_translate()
  5. caiyun currently supports from = {zh(中文), en, ja(日语), auto(自动识别)} and to = {en, ja, zh}, default from is auto

To use tencent (腾讯机器翻译) translate:

  1. go to https://console.cloud.tencent.com and register;
  2. login with your account, go to https://console.cloud.tencent.com/tmt to enable machine translation (启用机器翻译);
  3. go to https://console.cloud.tencent.com/cam/user/userType, create a sub-account, in Permissions (权限) - Permissions policy (权限策略), search and add QcloudTMTFullAccess;
  4. get your API keys at API keys (API 密钥) of the same page in step 3. set SecretId as the appid and SecretKey as secrets respectively with source = "tencent" using set_translate_option()
  5. have fun with tencent_translate()
  6. for supported languages, visit https://cloud.tencent.com/document/product/551/15611 for more information.

To use chatglm (智谱清言ChatGLM) translate:

  1. go to https://open.bigmodel.cn and register;
  2. login with your account, go to https://open.bigmodel.cn/usercenter/apikeys to get your API key;
  3. set the API key as key (no need for setting appid) with source = "chatglm" using set_translate_option()
  4. have fun with chatglm_translate()
  5. you can also set the model you prefer to use with the option user_model when using set_translate_option(), currently user_model can be set as glm-4 (by default), glm-4v, glm-3-turbo.

To use DeepSeek translate:

  1. go to https://platform.deepseek.com/ and register;
  2. login with your account, go to https://platform.deepseek.com/api_keys to get your API key;
  3. set the API key as key (no need for setting appid) with source = "dsk" using set_translate_option()
  4. have fun with dsk_translate()
  5. you can also set the model you prefer to use with the option user_model when using set_translate_option(), currently user_model can be set as deepseek-chat (by default), deepseek-coder.

Helper functions:

  • gene_summary() retrieves gene information from NCBI.
  • translate_ggplot() translates axis labels of a ggplot graph.
  • ydict() queries words from the Youdao dictionary.

:ideograph_advantage: Examples

library(fanyi)

##
## run `set_translate_option()` to setup
##

text <- '我都不知道做人该怎么办,总之报纸写啥就信啥,电视演啥我就看啥。'
translate(text, from='zh', to='en')

I don’t even know what to do as a person. Anyway, I believe whatever is written in the newspaper and watch whatever is shown on TV.

translate(text, from='zh', to='th')

ผมไม่รู้ว่าการเป็นมนุษย์ควรทําอย่างไร สรุปแล้วหนังสือพิมพ์เขียนอะไรก็เชื่ออย่างนั้น ทีวีเล่นอะไรก็อ่านอย่างนั้น

translate(text, from='zh', to='jp')

私は人間としてどうすればいいのか分からないが、とにかく新聞は何を書いても何を信じても、テレビは何を演じても私は何を見てもいい。

translate(text, from='zh', to='fra')

Je ne sais pas quoi faire en tant que personne, je crois ce que les journaux écrivent, je regarde ce que la télévision fait.

library(DOSE)
library(enrichplot)
data(geneList)
de <- names(geneList)[1:200]
x <- enrichDO(de)
p <- dotplot(x)
p2 <- translate_ggplot(p, axis='y')
p3 <- translate_ggplot(p, axis='y', to='kor')
p4 <- translate_ggplot(p, axis='y', to='ara')
aplot::plot_list(English = p, Chinese = p2, 
                Korean = p3, Arabic = p4, ncol=2)

ydict("cell")
    Explains: 细胞

    Web: https://m.youdao.com/m/result?lang=en&word=cell
symbol <- c("CCR7", "CD3E")
gene <- clusterProfiler::bitr(symbol, 
            fromType = 'SYMBOL', 
            toType = 'ENTREZID', 
            OrgDb = 'org.Hs.eg.db')

gene
  SYMBOL ENTREZID
1   CCR7     1236
2   CD3E      916
res <- gene_summary(gene$ENTREZID)
names(res)
[1] "uid"         "name"        "description" "summary"    
d <- data.frame(desc=res$description,
              desc2=translate(res$description))
d
                                            desc                   desc2
1                 C-C motif chemokine receptor 7    C-C基序趋化因子受体7
2 CD3 epsilon subunit of T-cell receptor complex T细胞受体复合物CD3ε亚基
res$summary

[1] The protein encoded by this gene is a member of the G protein-coupled receptor family. This receptor was identified as a gene induced by the Epstein-Barr virus (EBV), and is thought to be a mediator of EBV effects on B lymphocytes. This receptor is expressed in various lymphoid tissues and activates B and T lymphocytes. It has been shown to control the migration of memory T cells to inflamed tissues, as well as stimulate dendritic cell maturation. The chemokine (C-C motif) ligand 19 (CCL19/ECL) has been reported to be a specific ligand of this receptor. Signals mediated by this receptor regulate T cell homeostasis in lymph nodes, and may also function in the activation and polarization of T cells, and in chronic inflammation pathogenesis. Alternative splicing of this gene results in multiple transcript variants. [provided by RefSeq, Sep 2014]

[2] The protein encoded by this gene is t

View on GitHub
GitHub Stars60
CategoryDevelopment
Updated3d ago
Forks8

Languages

R

Security Score

80/100

Audited on Mar 31, 2026

No findings