Skip to content

Commit

Permalink
feat: get pons dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomeriko96 committed Mar 23, 2024
1 parent 68c38d5 commit 197dfc0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export(linguee_external_sources)
export(linguee_translation_examples)
export(linguee_word_translation)
export(mymemory_translate)
export(pons_dictionaries)
export(pons_translate)
export(qcri_get_domains)
export(qcri_get_language_pairs)
Expand Down
33 changes: 33 additions & 0 deletions R/pons_dictionaries.R
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)
}

1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ reference:
desc: Methods using Pons Translation services
contents:
- pons_translate
- pons_dictionaries

- title: QCRI Methods
desc: Methods using QCRI services
Expand Down
22 changes: 22 additions & 0 deletions man/pons_dictionaries.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 197dfc0

Please sign in to comment.