From 1f5bb462255057290f45c682e53d2a5012a4bbc6 Mon Sep 17 00:00:00 2001 From: Tomer Date: Sat, 23 Mar 2024 11:28:53 +0100 Subject: [PATCH] feat: get microsoft languages --- NAMESPACE | 1 + R/microsoft_supported_languages.R | 31 ++++++++++++++++++++++++++++ _pkgdown.yml | 5 +++++ man/microsoft_supported_languages.Rd | 22 ++++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 R/microsoft_supported_languages.R create mode 100644 man/microsoft_supported_languages.Rd diff --git a/NAMESPACE b/NAMESPACE index 2f19c17..3b825e0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/microsoft_supported_languages.R b/R/microsoft_supported_languages.R new file mode 100644 index 0000000..7036ce3 --- /dev/null +++ b/R/microsoft_supported_languages.R @@ -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) +} diff --git a/_pkgdown.yml b/_pkgdown.yml index adc72ad..4afead4 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -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: diff --git a/man/microsoft_supported_languages.Rd b/man/microsoft_supported_languages.Rd new file mode 100644 index 0000000..6d12e31 --- /dev/null +++ b/man/microsoft_supported_languages.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/microsoft_supported_languages.R +\name{microsoft_supported_languages} +\alias{microsoft_supported_languages} +\title{Get the set of languages currently supported by the Microsoft Translator API} +\usage{ +microsoft_supported_languages(scope = NULL) +} +\arguments{ +\item{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.} +} +\value{ +A list of supported languages for the specified groups. +} +\description{ +Get the set of languages currently supported by the Microsoft Translator API +} +\examples{ +\dontrun{ +microsoft_supported_languages(scope = "translation,transliteration,dictionary") +} +}