Package 'fanyi'

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

Help Index


translate

Description

Translate query sentences

Usage

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")

Arguments

x

query sentences

from

source language, i.e., the language to be translated

to

target language, i.e., the language to be translated into

Details

This function use online translator API (one of Baidu, bing, youdao, volcengine, caiyun, tencent and LLM) to translate query sentences

Value

the translated sentences

Author(s)

Guangchuang Yu

Examples

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')

fanyi_has_appkey

Description

test whether there has an appkey setting for the specific source

Usage

fanyi_has_appkey(source)

Arguments

source

one of the supported translate services

Value

logical value


gene_summary

Description

query gene information from NCBI

Usage

gene_summary(entrez)

Arguments

entrez

entrez gene IDs

Details

This function query gene information (including gene name, description and summary) from NCBI Gene database

Value

A data frame containing the information

Author(s)

Guangchuang Yu

Examples

## Not run: 
gene_summary('1236')

## End(Not run)

get_translate_text

Description

access translated text from online translator response

Usage

get_translate_text(response)

Arguments

response

return from the online translator

Value

translated text


name2sci

Description

convert species common name to scientific name

Usage

name2sci(x)

Arguments

x

common names

Details

The function query species common name via the NCBI Taxonomy database and return corresponding scientific name

Value

corresponding scientific names

Examples

## Not run: 
name2sci("tiger")

## End(Not run)

set_translate_option

Description

set appid and key of translation engine

Usage

set_translate_option(
  appid,
  key,
  source = "baidu",
  region = "southeastasia",
  user_dict = NULL,
  user_model = "glm-4"
)

Arguments

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 turbo, pro, standard and lite

Details

This function allows users to use their own appid and key

Value

No return value, called for side effects

Author(s)

Guangchuang Yu


set source of online translator service

Description

This function allows users to set the default source for translate() function

Usage

set_translate_source(source)

Arguments

source

translation engine

Value

No return value, called for side effects

Author(s)

Guangchuang Yu

Examples

set_translate_source("baidu")

search_gene

Description

search genes and return corresponding entrez ids

Usage

symbol2entrez(x, organism = "Homo sapiens")

search_gene(x, organism = "Homo sapiens")

Arguments

x

terms to search

organism

correpsonding organism of the input terms

Details

This function query genes (e.g., symbols) from NCBI Gene database and return corresponding entrez gene IDs

Value

A data frame with TERM and ENTREZ columns

Author(s)

Guangchuang Yu


translate_ggplot

Description

Translate axis label of a ggplot

Usage

translate_ggplot(plot, axis = "xy", from = "en", to = "zh")

Arguments

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

Details

This function use the translate() function to translate axis labels of a ggplot

Value

a translated ggplot object

Author(s)

Guangchuang Yu


ydict

Description

check English word in Youdao dictionary

Usage

ydict(word, web = FALSE)

Arguments

word

word to check

web

whether open youdao dict in web browser

Value

interpretation from youdao dictionary

Examples

## 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)