From b7757f6a285aeb06be68a6a0de5204ab270f97da Mon Sep 17 00:00:00 2001 From: Timon Date: Wed, 11 Mar 2026 11:15:48 +0100 Subject: [PATCH] Dynamically derive supported languages from JSON keys in report language selection --- r_app/90_CI_report_with_kpis_agronomic_support.Rmd | 6 +++++- r_app/90_report_utils.R | 8 ++++---- r_app/91_CI_report_with_kpis_cane_supply.Rmd | 6 +++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/r_app/90_CI_report_with_kpis_agronomic_support.Rmd b/r_app/90_CI_report_with_kpis_agronomic_support.Rmd index 66eda6b..6fe4f9b 100644 --- a/r_app/90_CI_report_with_kpis_agronomic_support.Rmd +++ b/r_app/90_CI_report_with_kpis_agronomic_support.Rmd @@ -468,7 +468,11 @@ tryCatch({ sheet_names <- c("main_translations", "status_translations", "figure_translations") # 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) { safe_log(paste("Specified language not supported, defaulting to 'en'"), "WARNING") } else { diff --git a/r_app/90_report_utils.R b/r_app/90_report_utils.R index 0d016bc..1ce61c2 100644 --- a/r_app/90_report_utils.R +++ b/r_app/90_report_utils.R @@ -658,11 +658,11 @@ cum_ci_plot <- function(pivotName, ci_quadrant_data = CI_quadrant, plot_type = " plot_data_both <- data_ci3 %>% dplyr::filter(season %in% unique_seasons) %>% dplyr::mutate( - ci_type_label = case_when( + ci_type_label = factor(case_when( ci_type == "mean_rolling_10_days" ~ rolling_mean_label, ci_type == "cumulative_CI" ~ cumulative_label, TRUE ~ ci_type - ), + ), levels = c(rolling_mean_label, cumulative_label)), 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 { DAH }, - ci_type_label = case_when( + ci_type_label = factor(case_when( ci_type == "value" ~ rolling_mean_label, ci_type == "cumulative_CI" ~ cumulative_label, TRUE ~ ci_type - ) + ), levels = c(rolling_mean_label, cumulative_label)) ) ggplot2::geom_smooth( data = benchmark_subset, diff --git a/r_app/91_CI_report_with_kpis_cane_supply.Rmd b/r_app/91_CI_report_with_kpis_cane_supply.Rmd index 8249499..72bd264 100644 --- a/r_app/91_CI_report_with_kpis_cane_supply.Rmd +++ b/r_app/91_CI_report_with_kpis_cane_supply.Rmd @@ -437,7 +437,11 @@ tryCatch({ sheet_names <- c("main_translations", "status_translations", "figure_translations") # 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) { safe_log(paste("Specified language not supported, defaulting to 'en'"), "WARNING") } else {