From 028e9e68f9d9bc89b6e0ef2cb71169f53cae15a1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 26 Feb 2024 22:33:17 +0100 Subject: [PATCH] [libcalamares] Add ${LANG} to process expansions --- src/libcalamares/utils/CommandList.cpp | 13 ++++++++++++- src/modules/shellprocess/shellprocess.conf | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/libcalamares/utils/CommandList.cpp b/src/libcalamares/utils/CommandList.cpp index 35295fedc..86efe1d38 100644 --- a/src/libcalamares/utils/CommandList.cpp +++ b/src/libcalamares/utils/CommandList.cpp @@ -14,6 +14,7 @@ #include "JobQueue.h" #include "compat/Variant.h" +#include "locale/Global.h" #include "utils/Logger.h" #include "utils/StringExpander.h" #include "utils/System.h" @@ -77,6 +78,16 @@ get_gs_expander( System::RunLocation location ) expander.insert( QStringLiteral( "USER" ), gs->value( "username" ).toString() ); } + if ( gs ) + { + const auto key = QStringLiteral( "LANG" ); + const QString lang = Calamares::Locale::readGS( *gs, key ); + if ( !lang.isEmpty() ) + { + expander.insert( key, lang ); + } + } + return expander; } @@ -106,7 +117,7 @@ CommandLine::expand( KMacroExpanderBase& expander ) const // .. and expand in each environment key=value string. QStringList e = m_environment; - std::for_each(e.begin(), e.end(), [&expander](QString & s) { expander.expandMacrosShellQuote(s);}); + std::for_each( e.begin(), e.end(), [ &expander ]( QString& s ) { expander.expandMacrosShellQuote( s ); } ); return { c, m_environment, m_timeout }; } diff --git a/src/modules/shellprocess/shellprocess.conf b/src/modules/shellprocess/shellprocess.conf index 881181a0d..87e31c58c 100644 --- a/src/modules/shellprocess/shellprocess.conf +++ b/src/modules/shellprocess/shellprocess.conf @@ -12,6 +12,9 @@ # system from the point of view of the command (when run in the target # system, e.g. when *dontChroot* is false, that will be `/`). # - `USER` is replaced by the username, set on the user page. +# - `LANG` is replaced by the language chosen for the user-interface +# of Calamares, set on the welcome page. This may not reflect the +# chosen system language from the locale page. # # Variables are written as `${var}`, e.g. `${ROOT}`. # Write `$$` to get a shell-escaped `\$` in the shell command.