Title: | Translate Words or Sentences via Online Translators |
---|---|
Description: | 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. |
Authors: | Guangchuang Yu [aut, cre, cph] , Guannan Chen [ctb], Difei Wang [ctb] |
Maintainer: | Guangchuang Yu <[email protected]> |
License: | Artistic-2.0 |
Version: | 0.0.8 |
Built: | 2024-11-18 03:11:36 UTC |
Source: | https://github.com/yulab-smu/fanyi |
Translate query sentences
baidu_translate(x, from = "en", to = "zh") bing_translate(x, from = "en", to = "zh") caiyun_translate(x, from = "auto", to = "zh") chatglm_translate(x, from = "en", to = "zh") deepseek_translate(x, from = "en", to = "zh") qwen_translate(x, from = "en", to = "zh") tencent_translate(x, from = "en", to = "zh") en2cn(x) cn2en(x) translate(x, from = "en", to = "zh") volcengine_translate(x, from = "en", to = "zh") youdao_translate(x, from = "en", to = "zh")
baidu_translate(x, from = "en", to = "zh") bing_translate(x, from = "en", to = "zh") caiyun_translate(x, from = "auto", to = "zh") chatglm_translate(x, from = "en", to = "zh") deepseek_translate(x, from = "en", to = "zh") qwen_translate(x, from = "en", to = "zh") tencent_translate(x, from = "en", to = "zh") en2cn(x) cn2en(x) translate(x, from = "en", to = "zh") volcengine_translate(x, from = "en", to = "zh") youdao_translate(x, from = "en", to = "zh")
x |
query sentences |
from |
source language, i.e., the language to be translated |
to |
target language, i.e., the language to be translated into |
This function use online translator API (one of Baidu, bing, youdao, volcengine, caiyun, tencent and LLM) to translate query sentences
the translated sentences
Guangchuang Yu
baidu_translate('hello world') library(fanyi) ## set your appid and key once in your R session # # set_translate_option(appid = 'your_appid', key = 'your_key', source = 'which_translation_service') # # translate('hello world', from = 'en', to = 'zh')
baidu_translate('hello world') library(fanyi) ## set your appid and key once in your R session # # set_translate_option(appid = 'your_appid', key = 'your_key', source = 'which_translation_service') # # translate('hello world', from = 'en', to = 'zh')
test whether there has an appkey setting for the specific source
fanyi_has_appkey(source)
fanyi_has_appkey(source)
source |
one of the supported translate services |
logical value
query gene information from NCBI
gene_summary(entrez)
gene_summary(entrez)
entrez |
entrez gene IDs |
This function query gene information (including gene name, description and summary) from NCBI Gene database
A data frame containing the information
Guangchuang Yu
## Not run: gene_summary('1236') ## End(Not run)
## Not run: gene_summary('1236') ## End(Not run)
access translated text from online translator response
get_translate_text(response)
get_translate_text(response)
response |
return from the online translator |
translated text
convert species common name to scientific name
name2sci(x)
name2sci(x)
x |
common names |
The function query species common name via the NCBI Taxonomy database and return corresponding scientific name
corresponding scientific names
## Not run: name2sci("tiger") ## End(Not run)
## Not run: name2sci("tiger") ## End(Not run)
set appid and key of translation engine
set_translate_option( appid, key, source = "baidu", region = "southeastasia", user_dict = NULL, user_model = "glm-4" )
set_translate_option( appid, key, source = "baidu", region = "southeastasia", user_dict = NULL, user_model = "glm-4" )
appid |
appid, "bing translate" will not use this input. |
key |
app key |
source |
translation engine |
region |
this is for bing use only, translation engine location, depends on your Azure service setting |
user_dict |
user defined dictionary ID, only used for 'source = "youdao"' |
user_model |
selected model used in for 'source = "chatglm"', one of |
This function allows users to use their own appid and key
No return value, called for side effects
Guangchuang Yu
This function allows users to set the default source for translate()
function
set_translate_source(source)
set_translate_source(source)
source |
translation engine |
No return value, called for side effects
Guangchuang Yu
set_translate_source("baidu")
set_translate_source("baidu")
search genes and return corresponding entrez ids
symbol2entrez(x, organism = "Homo sapiens") search_gene(x, organism = "Homo sapiens")
symbol2entrez(x, organism = "Homo sapiens") search_gene(x, organism = "Homo sapiens")
x |
terms to search |
organism |
correpsonding organism of the input terms |
This function query genes (e.g., symbols) from NCBI Gene database and return corresponding entrez gene IDs
A data frame with TERM and ENTREZ columns
Guangchuang Yu
Translate axis label of a ggplot
translate_ggplot(plot, axis = "xy", from = "en", to = "zh")
translate_ggplot(plot, axis = "xy", from = "en", to = "zh")
plot |
a ggplot object to be translated |
axis |
one of 'x', 'y' or 'xy' to select axis labels to be translated |
from |
source language, i.e., the language to be translated |
to |
target language, i.e., the language to be translated into |
This function use the translate()
function to translate axis labels of a ggplot
a translated ggplot object
Guangchuang Yu
check English word in Youdao dictionary
ydict(word, web = FALSE)
ydict(word, web = FALSE)
word |
word to check |
web |
whether open youdao dict in web browser |
interpretation from youdao dictionary
## Not run: ydict('panda') ydict(tiger) # unquoted word is supported # if using a word stored in a variable # x <- 'panda' ydict(!!rlang::sym(x)) ## End(Not run)
## Not run: ydict('panda') ydict(tiger) # unquoted word is supported # if using a word stored in a variable # x <- 'panda' ydict(!!rlang::sym(x)) ## End(Not run)