Skip to content

Commit

Permalink
Respect DESCRIPTION language.
Browse files Browse the repository at this point in the history
If the package authors have specified a Language in DESCRIPTION, default to that, rather than "en".
  • Loading branch information
jonthegeek committed Nov 6, 2024
1 parent ffe60d5 commit 2920e56
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ as_pkgdown <- function(pkg = ".", override = list()) {
if (!is.null(pkg$meta$url)) {
pkg$meta$url <- sub("/$", "", pkg$meta$url)
}

pkg$development <- meta_development(pkg)
pkg$prefix <- pkg$development$prefix

Expand All @@ -85,7 +85,7 @@ as_pkgdown <- function(pkg = ".", override = list()) {
pkg$dst_path <- path(pkg$dst_path, pkg$development$destination)
}

pkg$lang <- pkg$meta$lang %||% "en"
pkg$lang <- get_pkg_lang(pkg)
pkg$install_metadata <- config_pluck_bool(pkg, "deploy.install_metadata", FALSE)
pkg$figures <- meta_figures(pkg)
pkg$repo <- package_repo(pkg)
Expand All @@ -106,6 +106,18 @@ read_desc <- function(path = ".") {
desc::description$new(path)
}

get_pkg_lang <- function(pkg) {
if (!is.null(pkg$meta$lang)) {
return(pkg$meta$lang)
}

if (pkg$desc$has_fields("Language")) {
return(pkg$desc$get_field("Language"))
}

return("en")
}

get_bootstrap_version <- function(pkg,
template,
template_package = NULL,
Expand Down Expand Up @@ -270,7 +282,7 @@ extract_lifecycle <- function(x) {
fig <- extract_figure(desc)

if (!is.null(fig) && length(fig) > 0 && length(fig[[1]]) > 0) {
path <- as.character(fig[[1]][[1]])
path <- as.character(fig[[1]][[1]])
if (grepl("lifecycle", path)) {
name <- gsub("lifecycle-", "", path)
name <- path_ext_remove(name)
Expand Down Expand Up @@ -351,12 +363,12 @@ article_metadata <- function(path) {
if (path_ext(path) == "qmd") {
inspect <- quarto::quarto_inspect(path)
meta <- inspect$formats[[1]]$metadata

out <- list(
title = meta$title %||% "UNKNOWN TITLE",
desc = meta$description %||% NA_character_,
ext = path_ext(inspect$formats[[1]]$pandoc$`output-file`) %||% "html"
)
)
} else {
yaml <- rmarkdown::yaml_front_matter(path)
out <- list(
Expand Down

0 comments on commit 2920e56

Please sign in to comment.