Skip to content

Commit

Permalink
feat: get supported languages google
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomeriko96 committed Nov 19, 2023
1 parent 57a4b5c commit 3f20a38
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Imports:
httr,
magrittr,
purrr,
RCurl,
rlang,
rvest,
stringr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export("%>%")
export(create_translation_table)
export(google_get_supported_languages)
export(google_translate)
export(language_detect)
export(linguee_external_sources)
Expand Down
29 changes: 29 additions & 0 deletions R/google_get_supported_languages.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#' Get Supported Languages
#'
#' This function fetches the supported languages from the Google Cloud Translate documentation page.
#'
#' @return A data frame containing the supported languages and their corresponding ISO 639-1 codes.
#' @export
google_get_supported_languages <- function() {
# Define the URL of the webpage
url <- "https://cloud.google.com/translate/docs/languages"

# Check if the URL is available
if (!RCurl::url.exists(url)) {
stop("The URL is not available.")
}

# Read the HTML of the webpage
webpage <- rvest::read_html(url)

# Select the table from the webpage
table <- webpage %>% rvest::html_nodes('table')

# Convert the HTML table into a data frame
df <- table %>% rvest::html_table()

# Convert the first table in the list into a data frame
df_lang <- df[[1]] %>% tibble::as_tibble()

return(df_lang)
}
14 changes: 14 additions & 0 deletions man/google_get_supported_languages.Rd

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

0 comments on commit 3f20a38

Please sign in to comment.