R/print.R

Defines functions print.transdoc_text print.transdoc_website print.transdoc_help

Documented in print.transdoc_help

#' Print methods
#'
#' Print methods for objects generated by the transdoc package.
#' Browser opens Google Translate to translate the input documents.
#'
#' @inheritParams translate
#' @inheritParams base::print
#'
#' @examples
#' if (interactive()) {
#' print(translate("This text will be translated to Japanese", "ja"))
#' print(translate("https://transdoc.atusy.net/", "ja"))
#' print(translate(?base::c, "ja"))
#' }
#'
#' @return The input `x`.
#'
#' @name print-methods
#' @export
print.transdoc_help <- function(x, to = "default", ...) {
  if (check_offline(msg = "Being offline.", action = warning)) {
    class(x) <- "help_files_with_topic"
    print(x)
  } else {
    print.transdoc_website(translate(x, to = to, ...))
  }
}

#' @export
print.transdoc_website <- function(x, ...) {
  check_offline()
  x$to <- transdoc_to(x$to)
  utils::browseURL(url_google_translate(x$to, x$topic, type = "website"))
  invisible(x)
}

#' @export
print.transdoc_text <- function(x, ...) {
  check_offline()
  x$to <- transdoc_to(x$to)
  utils::browseURL(url_google_translate(x$to, x$topic, type = "text"))
  invisible(x)
}
atusy/transdoc documentation built on May 17, 2020, 4:38 p.m.