From cfd37fb499eca869fb139c663196c706d6f61e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig-=C3=98rjan=20Smelror?= Date: Wed, 14 Feb 2024 13:19:10 +0100 Subject: [PATCH] _msg: Refactor for localization --- qsgen2 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/qsgen2 b/qsgen2 index d2fcd09..2dab3ff 100755 --- a/qsgen2 +++ b/qsgen2 @@ -75,40 +75,40 @@ function _msg() { for arg in "$@"; do # Check if argument is a key in the localization array if [[ -n "${localization[$arg]}" ]]; then - # Append the localized message to full_msg - full_msg+="${localization[$arg]}" + # Append the localized message to full_msg, ensuring safe expansion + full_msg+="${(q)localization[$arg]}" else - # Argument not a key, treat as a literal string and append - full_msg+="$arg" + # Argument not a key, treat as a literal string and append, ensuring safe expansion + full_msg+="${(q)arg}" fi done # Apply color formatting based on type and use printf for safe output case $type in std) - printf "${green}%s${end}\n" "$full_msg" + printf "${green}%s${end}\n" "${full_msg}" ;; info) - printf "${yellow}%s${end}\n" "$full_msg" + printf "${yellow}%s${end}\n" "${full_msg}" ;; debug) - printf "${red}%s${end}\n" "$full_msg" + printf "${red}%s${end}\n" "${full_msg}" ;; other) - printf "${bold_yellow}%s${end}\n" "$full_msg" + printf "${bold_yellow}%s${end}\n" "${full_msg}" ;; sub) - printf "${magenta}%s${end}\n" "$full_msg" + printf "${magenta}%s${end}\n" "${full_msg}" ;; main) - printf "${white}${green_bg} %s ${end}\n" "$full_msg" + printf "${white}${green_bg} %s ${end}\n" "${full_msg}" ;; *) - printf "%s\n" "$full_msg" + printf "%s\n" "${full_msg}" ;; esac - echo "Debugging full_msg: $full_msg" + echo "Debugging full_msg: ${full_msg}" } function _version() {