-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68c38d5
commit 197dfc0
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#' Get the list of available dictionaries from PONS API | ||
#' | ||
#' @param language The language of the output (ISO 639-1 - two-letter codes). Supported languages are de, el, en, es, fr, it, pl, pt, ru, sl, tr, zh. | ||
#' @return A list of available dictionaries in the specified language. | ||
#' @export | ||
#' @examples | ||
#' \dontrun{ | ||
#' pons_dictionaries(language = "es") | ||
#' } | ||
pons_dictionaries <- function(language = "en") { | ||
# Check if the language is supported | ||
supported_languages <- c("de", "el", "en", "es", "fr", "it", "pl", "pt", "ru", "sl", "tr", "zh") | ||
if (!(language %in% supported_languages)) { | ||
stop("Unsupported language code. Please use one of the supported languages: ", paste(supported_languages, collapse = ", ")) | ||
} | ||
|
||
# Construct the API URL with the language parameter | ||
url <- paste0("https://api.pons.com/v1/dictionaries?language=", language) | ||
|
||
# Make the GET request | ||
response <- httr::GET(url) | ||
|
||
# Check if the request was successful | ||
if (httr::status_code(response) != 200) { | ||
stop("Failed to retrieve dictionaries. Status code: ", httr::status_code(response)) | ||
} | ||
|
||
# Parse the JSON response | ||
dictionaries <- jsonlite::fromJSON(httr::content(response, "text")) | ||
|
||
return(dictionaries) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.