R/available_languages2.R

Defines functions available_languages2

Documented in available_languages2

#' List supported languages of DeepL API Free
#'
#' \code{available_languages2} list all supported languages of DeepL API Free.
#'
#' @importFrom httr POST content
#' @importFrom purrr map_chr
#' @importFrom tibble tibble
#'
#' @param auth_key authentication key.
#'
#' @details To get an authentication key, you need to register for a DeepL API Free
#'     account (\url{https://www.deepl.com/pro#developer}).
#'
#' @references \href{https://www.deepl.com/pro#developer}{DeepL API documentations}
#'
#' @export
#'
#' @examples
#' \dontrun{
#' available_languages2(auth_key = "my_key")
#' }
#'
available_languages2 <- function(auth_key = "your_key") {

  # DeepL API call
  response <- httr::POST(
    url = "https://api-free.deepl.com/v2/languages",
    httr::add_headers("Authorization" = paste("DeepL-Auth-Key", auth_key))
    )

  response_check(response)

  tibble::tibble(
    language = purrr::map_chr(httr::content(response), "language"),
    name = purrr::map_chr(httr::content(response), "name")
    )

}

Try the deeplr package in your browser

Any scripts or data that you put into this service are public.

deeplr documentation built on Nov. 8, 2023, 1:09 a.m.