-
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.
feat: check validity of google language codes using internal data
- Loading branch information
Showing
9 changed files
with
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,6 @@ Suggests: | |
text2vec | ||
Config/testthat/edition: 3 | ||
VignetteBuilder: knitr | ||
Depends: | ||
R (>= 2.10) | ||
LazyData: true |
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,23 @@ | ||
#' Check if a language code is valid | ||
#' | ||
#' This function checks if a given language code is in the `google_supported_languages` dataset. | ||
#' | ||
#' @param language_code The language code to check. | ||
#' @return A logical value indicating if the language code is valid. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' google_is_valid_language_code("en") # TRUE | ||
#' google_is_valid_language_code("fr") # TRUE | ||
#' google_is_valid_language_code("xx") # FALSE | ||
google_is_valid_language_code <- function(language_code) { | ||
if (language_code == "auto") { | ||
return(TRUE) | ||
} | ||
|
||
if (language_code %in% polyglotr::google_supported_languages$`ISO-639 code`) { | ||
return(TRUE) | ||
} else { | ||
return(FALSE) | ||
} | ||
} |
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,8 @@ | ||
#' Google Supported Languages | ||
#' | ||
#' This dataset contains the language names and iso codes of languages supported by Google Translate API. | ||
#' | ||
#' @format A data frame with two variables: language_name and iso_code | ||
#' @source Google Translate API | ||
#' @keywords data | ||
"google_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
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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