-
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
197dfc0
commit 1f5bb46
Showing
4 changed files
with
59 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,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) | ||
} |
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.