From 769661cee02fd5c24e4238186dc0024d6ed4d447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig-=C3=98rjan=20Smelror?= Date: Wed, 14 Feb 2024 13:06:44 +0100 Subject: [PATCH] _msg: Refactor --- include/qsgen2/lang/nb_NO | 3 ++- qsgen2 | 22 ++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/include/qsgen2/lang/nb_NO b/include/qsgen2/lang/nb_NO index 08b893c..a9ef9ad 100644 --- a/include/qsgen2/lang/nb_NO +++ b/include/qsgen2/lang/nb_NO @@ -1,5 +1,6 @@ typeset -A localization -localization=(_qsgen2_msg_2 "- Tvungen oppdatering: Genererer alt" +localization=( +_qsgen2_msg_2 "- Tvungen oppdatering: Genererer alt" _qsgen2_msg_3 "* %SCRIPT_NAME% kan ikke analysere dette nettstedet. Avslutter. *" _qsgen2_msg_4 "Vennligst installer Pandoc." _qsgen2_msg_5 "Ingen gyldig generator funnet. Er du sikker på at du har valgt riktig generator i 'config'?" diff --git a/qsgen2 b/qsgen2 index 4cb1899..738d854 100755 --- a/qsgen2 +++ b/qsgen2 @@ -16,7 +16,7 @@ QSGEN="Quick Site Generator 2" # Set to true or false # This will show debug information from every function in this script # You can also set debug=true in a single function if you want to debug only that specific one. -globaldebug=true +globaldebug=false # Use Zsh fpath to set the path to some extra functions fpath=(${HOME}/bin/include/common ${HOME}/bin/include/qsgen2/lang $fpath) @@ -69,19 +69,17 @@ fi function _msg() { local type=$1 - shift # Remove the first argument so $@ now contains only message keys or parts - + shift # Remove the first argument (type) so $@ now contains only keys or additional strings + local full_msg="" - for part in "$@"; do - if [[ -n "${localization[$part]}" ]]; then - # Part is a localization key - part="${localization[$part]}" - elif [[ "$part" == "%SCRIPT_NAME%" ]]; then - # Special handling for script name placeholder - part=${0:t} + for key in "$@"; do + if [[ "${localization[$key]}" ]]; then + # If key exists in the localization array, append its value + full_msg+="${localization[$key]}" + else + # If key does not exist, treat it as a literal string (useful for dynamic content like ${0:t}) + full_msg+="$key" fi - # Append part to the full message - full_msg+="$part" done # Apply color formatting based on type and use printf for safe output