Skip to content

Commit

Permalink
without side effect
Browse files Browse the repository at this point in the history
  • Loading branch information
GuangchuangYu committed Dec 13, 2023
1 parent 2fa8e80 commit 1a05b2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
15 changes: 14 additions & 1 deletion R/baidu-translate.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,24 @@ set_translate_appkey <- function(appid, key) {
options(yulab_translate = list(appid = appid, key = key))
}

get_translate_source <- function() {
getOption('yulab_translate_source', "baidu")
}

get_translate_appkey <- function() {
getOption('yulab_translate')
res <- getOption('yulab_translate')
if (!is.null(res)) return(res)

src <- get_translate_source()
if (src == "baidu") {
res <- getOption('yulab_translate', .baidu_appkey)
}
return(res)
}




#' Translate query sentence
#'
#' This function use the Baidu fanyi API to translate query sentences
Expand Down
7 changes: 1 addition & 6 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,5 @@
}



.onAttach <- function(libname, pkgname) {
set_translate_source("baidu")
set_translate_option(appid = "20231211001907382", key = "UM3Z6c5iQMOYNkkN5dzV")
}

.baidu_appkey <- list(appid = "20231211001907382", key = "UM3Z6c5iQMOYNkkN5dzV")

0 comments on commit 1a05b2e

Please sign in to comment.