_msg: Refactor
This commit is contained in:
		@@ -1,6 +1,5 @@
 | 
				
			|||||||
typeset -A localization
 | 
					typeset -A localization
 | 
				
			||||||
localization=(
 | 
					localization=(
 | 
				
			||||||
_qsgen2_msg_1 "Bruk: qsgen2 add \"Nettstedsnavn\" \"sti/til/prosjekt\""
 | 
					 | 
				
			||||||
_qsgen2_msg_2 "- Tvungen oppdatering: Genererer alt"
 | 
					_qsgen2_msg_2 "- Tvungen oppdatering: Genererer alt"
 | 
				
			||||||
_qsgen2_msg_3 "* %SCRIPT_NAME% kan ikke analysere dette nettstedet. Avslutter. *"
 | 
					_qsgen2_msg_3 "* %SCRIPT_NAME% kan ikke analysere dette nettstedet. Avslutter. *"
 | 
				
			||||||
_qsgen2_msg_4 "Vennligst installer Pandoc."
 | 
					_qsgen2_msg_4 "Vennligst installer Pandoc."
 | 
				
			||||||
@@ -18,7 +17,7 @@ _blog_cache_msg_2 "1. _blog_cache: ${blog_file}"
 | 
				
			|||||||
_blog_cache_msg_3 "2. _blog_cache: nåværende cache: ${current_hash}"
 | 
					_blog_cache_msg_3 "2. _blog_cache: nåværende cache: ${current_hash}"
 | 
				
			||||||
_blog_cache_msg_4 "3. _blog_cache: ny cache-fil: ${blog_file}$"
 | 
					_blog_cache_msg_4 "3. _blog_cache: ny cache-fil: ${blog_file}$"
 | 
				
			||||||
_blog_cache_msg_5 "4. _blog_cache: ny nåværende cache: ${current_hash}"
 | 
					_blog_cache_msg_5 "4. _blog_cache: ny nåværende cache: ${current_hash}"
 | 
				
			||||||
_pages_cache_msg_1 "SIDERS HASH VERDI: ${pages_cache[${name}]}"
 | 
					_pages_cache_msg_1 "_pages_cache: PAGES HASH VERDI: ${pages_cache[${name}]}"
 | 
				
			||||||
_pages_cache_msg_2 "1. pages_cache: ${pages_cache[$file]}"
 | 
					_pages_cache_msg_2 "1. pages_cache: ${pages_cache[$file]}"
 | 
				
			||||||
_pages_cache_msg_3 "1. _pages_cache: nåværende cache: ${current_hash}"
 | 
					_pages_cache_msg_3 "1. _pages_cache: nåværende cache: ${current_hash}"
 | 
				
			||||||
_pages_cache_msg_4 "2. _pages_cache: sidefil: ${pages_cache[$file]}"
 | 
					_pages_cache_msg_4 "2. _pages_cache: sidefil: ${pages_cache[$file]}"
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										42
									
								
								qsgen2
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								qsgen2
									
									
									
									
									
								
							@@ -56,48 +56,50 @@ if (${globaldebug}); then
 | 
				
			|||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function _msg() {
 | 
					function _msg() {
 | 
				
			||||||
    # Usage: _msg <type> "key"
 | 
					 | 
				
			||||||
    local type=$1
 | 
					    local type=$1
 | 
				
			||||||
    local key=$2
 | 
					    shift  # Remove the first argument so $@ now contains only message keys or parts
 | 
				
			||||||
    local msg=${localization[$key]}
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    # Check if message exists for the key
 | 
					    local full_msg=""
 | 
				
			||||||
    if [[ -z "$msg" ]]; then
 | 
					    for part in "$@"; do
 | 
				
			||||||
        printf "Localization key '%s' not found.\n" "$key"
 | 
					        if [[ -n "${localization[$part]}" ]]; then
 | 
				
			||||||
        return
 | 
					            # Part is a localization key
 | 
				
			||||||
    fi
 | 
					            part="${localization[$part]}"
 | 
				
			||||||
 | 
					        elif [[ "$part" == "%SCRIPT_NAME%" ]]; then
 | 
				
			||||||
    # Dynamic replacement for known placeholders
 | 
					            # Special handling for script name placeholder
 | 
				
			||||||
    msg=${msg//"%SCRIPT_NAME%"/${0:t}}
 | 
					            part=${0:t}
 | 
				
			||||||
 | 
					        fi
 | 
				
			||||||
 | 
					        # Append part to the full message
 | 
				
			||||||
 | 
					        full_msg+="$part"
 | 
				
			||||||
 | 
					    done
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    # Apply color formatting based on type and use printf for safe output
 | 
					    # Apply color formatting based on type and use printf for safe output
 | 
				
			||||||
    case ${type} in
 | 
					    case $type in
 | 
				
			||||||
        std)
 | 
					        std)
 | 
				
			||||||
            printf "${green}%s${end}\n" "$msg"
 | 
					            printf "${green}%s${end}\n" "$full_msg"
 | 
				
			||||||
            ;;
 | 
					            ;;
 | 
				
			||||||
        info)
 | 
					        info)
 | 
				
			||||||
            printf "${yellow}%s${end}\n" "$msg"
 | 
					            printf "${yellow}%s${end}\n" "$full_msg"
 | 
				
			||||||
            ;;
 | 
					            ;;
 | 
				
			||||||
        debug)
 | 
					        debug)
 | 
				
			||||||
            printf "${red}%s${end}\n" "$msg"
 | 
					            printf "${red}%s${end}\n" "$full_msg"
 | 
				
			||||||
            ;;
 | 
					            ;;
 | 
				
			||||||
        other)
 | 
					        other)
 | 
				
			||||||
            printf "${bold_yellow}%s${end}\n" "$msg"
 | 
					            printf "${bold_yellow}%s${end}\n" "$full_msg"
 | 
				
			||||||
            ;;
 | 
					            ;;
 | 
				
			||||||
        sub)
 | 
					        sub)
 | 
				
			||||||
            printf "${magenta}%s${end}\n" "$msg"
 | 
					            printf "${magenta}%s${end}\n" "$full_msg"
 | 
				
			||||||
            ;;
 | 
					            ;;
 | 
				
			||||||
        main)
 | 
					        main)
 | 
				
			||||||
            printf "${white}${green_bg} %s ${end}\n" "$msg"
 | 
					            printf "${white}${green_bg} %s ${end}\n" "$full_msg"
 | 
				
			||||||
            ;;
 | 
					            ;;
 | 
				
			||||||
        *)
 | 
					        *)
 | 
				
			||||||
            printf "%s\n" "$msg"
 | 
					            printf "%s\n" "$full_msg"
 | 
				
			||||||
            ;;
 | 
					            ;;
 | 
				
			||||||
    esac
 | 
					    esac
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function _version() {
 | 
					function _version() {
 | 
				
			||||||
  _msg info "_qsgen2_msg_7$(strftime "%Y")"
 | 
					  _msg info "_qsgen2_msg_7" "$(strftime "%Y")"
 | 
				
			||||||
  echo "${yellow}- https://github.com/kekePower/qsgen2/${end}"
 | 
					  echo "${yellow}- https://github.com/kekePower/qsgen2/${end}"
 | 
				
			||||||
  _msg info "_qsgen2_msg_8"
 | 
					  _msg info "_qsgen2_msg_8"
 | 
				
			||||||
  exit
 | 
					  exit
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user