Skip to content

Commit

Permalink
update: roxygen comments for wmcloud function
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomeriko96 committed Jan 26, 2024
1 parent 165996f commit af2ffc9
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 18 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ URL: https://github.com/Tomeriko96/polyglotr/,
BugReports: https://github.com/Tomeriko96/polyglotr/issues
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Imports:
dplyr,
httr,
Expand Down
47 changes: 36 additions & 11 deletions R/wmcloud_translate.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,45 @@
#' Translate text using WMCloud
#' Translate content using WMCloud
#'
#' This function sends a POST request to the WMCloud translation API with the specified parameters,
#' parses the JSON response, and returns the translated text.
#' parses the JSON response, and returns the translated content.
#'
#' @param text The text to translate.
#' @param content The content to translate. Can be plain text, a URL (for a webpage), a JSON string, or a Markdown string.
#' @param target_language The target language for the translation (default is "en").
#' @param source_language The source language of the text (default is "en").
#' @param source_language The source language of the content (default is "en").
#' @param format The format of the content ("html", "json", "markdown", "text", "svg", "webpage").
#' @param model The model to use for the translation (only "nllb200-600M" is currently known to work).
#'
#' @return The translated text.
#' @return The translated content.
#'
#' @examples
#' \dontrun{
#' # Translate plain text
#' wmcloud_translate("rijst",
#' target_language = "es",
#' source_language = "nl", format = "text")
#'
#' # Translate a webpage
#' wmcloud_translate("https://en.m.wikivoyage.org/wiki/Goes",
#' target_language = "es",
#' source_language = "en", format = "webpage")
#'
#' # Translate JSON content
#' wmcloud_translate('{
#' "id": 1,
#' "title": "Chicken Biryani",
#' "description": "Chicken Biryani is a savory chicken and rice dish",
#' "ingredients": [ "Vegetable oil", "Garlic", "Ginger" ,"Rice"]
#' }
#' ', target_language = "es", source_language = "en", format = "json")
#'
#' # Translate Markdown content
#' wmcloud_translate('# Heading
#'
#' This is a [link to Wikipedia](https://wikipedia.org)
#' ', target_language = "es", source_language = "en", format = "markdown")
#' }
#' @export
wmcloud_translate <- function(text,
wmcloud_translate <- function(content,
target_language = "en",
source_language = "en",
format = "text",
Expand Down Expand Up @@ -39,7 +67,7 @@ wmcloud_translate <- function(text,
target_language = target_language,
format = format,
model = model,
content = text
content = content
)

# Convert the list to a JSON string
Expand All @@ -59,11 +87,8 @@ wmcloud_translate <- function(text,
# Parse the response
result <- httr::content(response, "parsed")

# Extract the translated text from the response
# Extract the translated content from the response
translation <- result$translation

return(translation)
}



40 changes: 34 additions & 6 deletions man/wmcloud_translate.Rd

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

0 comments on commit af2ffc9

Please sign in to comment.