Dynamically derive supported languages from JSON keys in report language selection

This commit is contained in:
Timon 2026-03-11 11:15:48 +01:00
parent d794f31460
commit b7757f6a28
3 changed files with 14 additions and 6 deletions

View file

@ -468,7 +468,11 @@ tryCatch({
sheet_names <- c("main_translations", "status_translations", "figure_translations") sheet_names <- c("main_translations", "status_translations", "figure_translations")
# Determine language column (fall back to English) # Determine language column (fall back to English)
lang_col <- if (language %in% c("en", "es", "pt-br")) language else "en" # Supported languages are derived dynamically from the JSON keys
supported_langs <- unique(unlist(lapply(translations_json, function(sheet) {
lapply(sheet, names)
})))
lang_col <- if (language %in% supported_langs) language else "en"
if (lang_col != language) { if (lang_col != language) {
safe_log(paste("Specified language not supported, defaulting to 'en'"), "WARNING") safe_log(paste("Specified language not supported, defaulting to 'en'"), "WARNING")
} else { } else {

View file

@ -658,11 +658,11 @@ cum_ci_plot <- function(pivotName, ci_quadrant_data = CI_quadrant, plot_type = "
plot_data_both <- data_ci3 %>% plot_data_both <- data_ci3 %>%
dplyr::filter(season %in% unique_seasons) %>% dplyr::filter(season %in% unique_seasons) %>%
dplyr::mutate( dplyr::mutate(
ci_type_label = case_when( ci_type_label = factor(case_when(
ci_type == "mean_rolling_10_days" ~ rolling_mean_label, ci_type == "mean_rolling_10_days" ~ rolling_mean_label,
ci_type == "cumulative_CI" ~ cumulative_label, ci_type == "cumulative_CI" ~ cumulative_label,
TRUE ~ ci_type TRUE ~ ci_type
), ), levels = c(rolling_mean_label, cumulative_label)),
is_latest = season == latest_season # Flag for latest season is_latest = season == latest_season # Flag for latest season
) )
@ -708,11 +708,11 @@ cum_ci_plot <- function(pivotName, ci_quadrant_data = CI_quadrant, plot_type = "
} else { } else {
DAH DAH
}, },
ci_type_label = case_when( ci_type_label = factor(case_when(
ci_type == "value" ~ rolling_mean_label, ci_type == "value" ~ rolling_mean_label,
ci_type == "cumulative_CI" ~ cumulative_label, ci_type == "cumulative_CI" ~ cumulative_label,
TRUE ~ ci_type TRUE ~ ci_type
) ), levels = c(rolling_mean_label, cumulative_label))
) )
ggplot2::geom_smooth( ggplot2::geom_smooth(
data = benchmark_subset, data = benchmark_subset,

View file

@ -437,7 +437,11 @@ tryCatch({
sheet_names <- c("main_translations", "status_translations", "figure_translations") sheet_names <- c("main_translations", "status_translations", "figure_translations")
# Determine language column (fall back to English) # Determine language column (fall back to English)
lang_col <- if (language %in% c("en", "es-mx", "pt-br", "sw")) language else "en" # Supported languages are derived dynamically from the JSON keys
supported_langs <- unique(unlist(lapply(translations_json, function(sheet) {
lapply(sheet, names)
})))
lang_col <- if (language %in% supported_langs) language else "en"
if (lang_col != language) { if (lang_col != language) {
safe_log(paste("Specified language not supported, defaulting to 'en'"), "WARNING") safe_log(paste("Specified language not supported, defaulting to 'en'"), "WARNING")
} else { } else {