Skip to content
Draft
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Imports:
yaml (>= 2.3.8)
Suggests:
blogdown,
cld3,
clipr,
fs,
gert,
httptest2,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Generated by roxygen2: do not edit by hand

export(deepl_branch_update)
export(deepl_languages)
export(deepl_translate)
export(deepl_translate_clipboard)
export(deepl_translate_hugo)
export(deepl_translate_markdown_string)
export(deepl_translate_quarto)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# babeldown (development version)

* New function `deepl_branch_update()`. (#90)
11 changes: 11 additions & 0 deletions R/cli.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cli_alert_success <- function(text, .envir = parent.frame()) {
if (!getOption("babeldown.quiet", FALSE)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mpadge look at me following part of our blog post's advice 😇

cli::cli_alert_success(text, .envir = .envir)
}
}

cli_alert_info <- function(text, .envir = parent.frame()) {
if (!getOption("babeldown.quiet", FALSE)) {
cli::cli_alert_info(text, .envir = .envir)
}
}
60 changes: 60 additions & 0 deletions R/config.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
read_config <- function(repo) {
config_repo <- file.path(repo, "_deepl.yml")

if (!file.exists(config_repo)) {
cli::cli_abort("Can't find {.repo {config_repo}}")
}

yaml::read_yaml(config_repo)
}

read_preferences <- function(repo = ".", source_lang, target_lang) {
config <- read_config(repo) |>
purrr::pluck("preferences") |>
purrr::keep(\(x) x$source == source_lang) |>
purrr::keep(\(x) x$target == target_lang)
if (length(config) == 0) {
cli::cli_abort(
"Can't find preferences for source language {source_lang}
and target language {target_lang}."
)
}

if (length(config) > 1) {
cli::cli_abort(
"More than one list of preferences for source language {.val {source_lang}}
and target language {.val {target_lang}}."
)
}

unlist(config, recursive = FALSE)
}

read_excludes <- function(repo = ".") {
read_config(repo) |>
purrr::pluck("excludes")
}

read_excludes <- function(repo = ".") {
read_config(repo) |>
purrr::pluck("targets")
}

read_extension <- function(repo = ".", extension) {
config <- read_config(repo) |>
purrr::pluck("languages") |>
purrr::keep(\(x) x$extension == extension)
if (length(config) == 0) {
cli::cli_abort(
"Can't find settings for extension {.val {extension}}."
)
}

if (length(config) > 1) {
cli::cli_abort(
"More than one list of settings for extension {.val {extension}}."
)
}

unlist(config, recursive = FALSE)
}
Loading
Loading