Skip to content

Commit

Permalink
feat: get microsoft languages
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomeriko96 committed Mar 23, 2024
1 parent 197dfc0 commit 1f5bb46
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export(language_detect)
export(linguee_external_sources)
export(linguee_translation_examples)
export(linguee_word_translation)
export(microsoft_supported_languages)
export(mymemory_translate)
export(pons_dictionaries)
export(pons_translate)
Expand Down
31 changes: 31 additions & 0 deletions R/microsoft_supported_languages.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#' Get the set of languages currently supported by the Microsoft Translator API
#'
#' @param scope (optional) A comma-separated list of names defining the group of languages to return. Allowed group names are: translation, transliteration, and dictionary. If no scope is given, then all groups are returned.
#' @return A list of supported languages for the specified groups.
#' @export
#' @examples
#' \dontrun{
#' microsoft_supported_languages(scope = "translation,transliteration,dictionary")
#' }
microsoft_supported_languages <- function(scope = NULL) {
# Construct the API URL with the required parameters
url <- "https://api.cognitive.microsofttranslator.com/languages?api-version=3.0"

# Add the scope parameter to the URL if provided
if (!is.null(scope)) {
url <- paste0(url, "&scope=", scope)
}

# Make the GET request
response <- httr::GET(url)

# Check if the request was successful
if (httr::status_code(response) != 200) {
stop("Failed to retrieve supported languages. Status code: ", httr::status_code(response))
}

# Parse the JSON response
supported_languages <- jsonlite::fromJSON(httr::content(response, "text"))

return(supported_languages)
}
5 changes: 5 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ reference:
- linguee_translation_examples
- linguee_word_translation

-title: Microsoft Methods
desc: Methods using Microsoft Translation services
content:
- microsoft_supported_languages

- title: MyMemory Methods
desc: Methods using MyMemory Translation services
contents:
Expand Down
22 changes: 22 additions & 0 deletions man/microsoft_supported_languages.Rd

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

0 comments on commit 1f5bb46

Please sign in to comment.