Remove tools directory from git
This commit is contained in:
parent
881385b29d
commit
834dabf403
@ -1,144 +0,0 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
# Script to extract and organize user-facing strings from the codebase
|
||||
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
SOURCE_DIR="$(dirname "$0")/.."
|
||||
LANG_DIR="${SOURCE_DIR}/include/qsgen2/lang"
|
||||
OUTPUT_FILE="${LANG_DIR}/extracted_messages.txt"
|
||||
|
||||
# Create output directory if it doesn't exist
|
||||
mkdir -p "$(dirname "$OUTPUT_FILE")"
|
||||
|
||||
# Initialize output file
|
||||
cat > "$OUTPUT_FILE" << 'EOF'
|
||||
# Quick Site Generator 2 - Extracted Messages
|
||||
# This file contains all user-facing strings extracted from the codebase
|
||||
# Generated on: $(date)
|
||||
|
||||
# Format:
|
||||
# [message_id] = "message"
|
||||
# Where message_id is in the format: category_subject_description
|
||||
# Example: error_file_not_found = "File not found: %s"
|
||||
|
||||
# Categories:
|
||||
# - config: Configuration related messages
|
||||
# - file: File operation messages
|
||||
# - build: Build process messages
|
||||
# - blog: Blog system messages
|
||||
# - page: Page system messages
|
||||
# - error: Error messages
|
||||
# - warning: Warning messages
|
||||
# - info: Informational messages
|
||||
# - debug: Debug messages
|
||||
|
||||
# Message Dictionary
|
||||
[messages]
|
||||
|
||||
EOF
|
||||
|
||||
# Function to add a message to the output file
|
||||
add_message() {
|
||||
local category="$1"
|
||||
local subject="$2"
|
||||
local description="$3"
|
||||
local message="$4"
|
||||
|
||||
# Generate message ID
|
||||
local msg_id="${category}_${subject}_${description}"
|
||||
|
||||
# Clean up the message ID
|
||||
msg_id=$(echo "$msg_id" | tr '[:upper:]' '[:lower:]' | tr ' ' '_' | sed 's/[^a-z0-9_]/_/g' | sed 's/__*/_/g' | sed 's/^_//;s/_$//')
|
||||
|
||||
# Add to output file
|
||||
echo "${msg_id} = \"${message}\"" >> "$OUTPUT_FILE"
|
||||
}
|
||||
|
||||
# Extract messages from _msg calls
|
||||
echo "# Extracting messages from _msg calls..."
|
||||
|
||||
grep -r --include="*.zsh" --include="*.sh" -h "_msg " "$SOURCE_DIR" | \
|
||||
grep -v '^\s*#' | \
|
||||
grep -v '^\s*$' | \
|
||||
while read -r line; do
|
||||
# Extract message type and content
|
||||
msg_type=$(echo "$line" | awk -F'"' '{print $1}' | awk '{print $NF}' | tr -d ' ')
|
||||
msg_content=$(echo "$line" | sed -E 's/.*_msg[[:space:]]+[^[:space:]]+[[:space:]]+["]([^"]+)["].*/\1/')
|
||||
|
||||
# Skip if we couldn't extract content
|
||||
if [[ "$msg_content" == "$line" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Determine category based on message type
|
||||
case "$msg_type" in
|
||||
error)
|
||||
category="error"
|
||||
;;
|
||||
warning)
|
||||
category="warning"
|
||||
;;
|
||||
info|other)
|
||||
category="info"
|
||||
;;
|
||||
debug)
|
||||
category="debug"
|
||||
;;
|
||||
*)
|
||||
category="info"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Generate a description from the message content
|
||||
description=$(echo "$msg_content" | \
|
||||
head -n 1 | \
|
||||
tr '[:upper:]' '[:lower:]' | \
|
||||
sed 's/[^a-z0-9 ]/ /g' | \
|
||||
sed 's/ */ /g' | \
|
||||
cut -c1-30 | \
|
||||
tr ' ' '_' | \
|
||||
sed 's/_$//')
|
||||
|
||||
# Add the message
|
||||
add_message "$category" "general" "$description" "$msg_content"
|
||||
done
|
||||
|
||||
# Extract messages from echo/print statements
|
||||
echo "# Extracting messages from echo/print statements..."
|
||||
|
||||
grep -r --include="*.zsh" --include="*.sh" -h -E 'echo|printf|print' "$SOURCE_DIR" | \
|
||||
grep -v '^\s*#' | \
|
||||
grep -v '^\s*$' | \
|
||||
grep -v '\\n' | \
|
||||
grep -v '\$\|`' | \
|
||||
grep -E '".*[a-z].*"' | \
|
||||
while read -r line; do
|
||||
# Extract message content
|
||||
msg_content=$(echo "$line" | grep -o '"[^"]*"' | head -n 1 | tr -d '"')
|
||||
|
||||
# Skip if no content
|
||||
if [[ -z "$msg_content" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Skip common debug/technical messages
|
||||
if [[ "$msg_content" =~ ^[^a-zA-Z]*$ ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Add as an info message
|
||||
description=$(echo "$msg_content" | \
|
||||
head -n 1 | \
|
||||
tr '[:upper:]' '[:lower:]' | \
|
||||
sed 's/[^a-z0-9 ]/ /g' | \
|
||||
sed 's/ */ /g' | \
|
||||
cut -c1-30 | \
|
||||
tr ' ' '_' | \
|
||||
sed 's/_$//')
|
||||
|
||||
add_message "info" "general" "$description" "$msg_content"
|
||||
done
|
||||
|
||||
echo "Message extraction complete. Review the output in $OUTPUT_FILE"
|
@ -1,63 +0,0 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
# Script to help migrate message strings to the new format
|
||||
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
SOURCE_DIR="$(dirname "$0")/.."
|
||||
LANG_DIR="${SOURCE_DIR}/include/qsgen2/lang"
|
||||
OUTPUT_FILE="${LANG_DIR}/message_migration.txt"
|
||||
|
||||
# Create output directory if it doesn't exist
|
||||
mkdir -p "$(dirname "$OUTPUT_FILE")"
|
||||
|
||||
# Initialize output file
|
||||
cat > "$OUTPUT_FILE" << EOF
|
||||
# Quick Site Generator 2 - Message Migration
|
||||
# This file helps migrate from old message format to the new format
|
||||
# Generated on: $(date)
|
||||
#
|
||||
# Format:
|
||||
# OLD_ID = "message"
|
||||
# NEW_ID = "new.message.id"
|
||||
#
|
||||
# [Additional notes]
|
||||
|
||||
EOF
|
||||
|
||||
# Find all _msg calls in the codebase
|
||||
echo "# Messages from _msg calls" >> "$OUTPUT_FILE"
|
||||
grep -r --include="*.zsh" --include="*.sh" -h "_msg " "$SOURCE_DIR" | \
|
||||
grep -o "_msg \w\+ \"[^\"]\+" | \
|
||||
sort -u | \
|
||||
while read -r line; do
|
||||
# Extract message type and content
|
||||
msg_type=$(echo "$line" | awk '{print $2}')
|
||||
msg_content=$(echo "$line" | cut -d'"' -f2)
|
||||
|
||||
# Generate a message ID based on content
|
||||
msg_id=$(echo "$msg_content" | \
|
||||
tr '[:upper:]' '[:lower:]' | \
|
||||
sed 's/[^a-z0-9]/_/g' | \
|
||||
sed 's/__*/_/g' | \
|
||||
sed 's/^_//;s/_$//')
|
||||
|
||||
# Add to output file
|
||||
echo "# $line" >> "$OUTPUT_FILE"
|
||||
echo "msg_${msg_id} = \"${msg_content}\"" >> "$OUTPUT_FILE"
|
||||
echo >> "$OUTPUT_FILE"
|
||||
done
|
||||
|
||||
# Find all existing message IDs in language files
|
||||
echo -e "\n# Existing message IDs in language files" >> "$OUTPUT_FILE"
|
||||
find "$LANG_DIR" -type f -name "*.en" -o -name "en_*" | while read -r langfile; do
|
||||
echo "## From $(basename "$langfile"):" >> "$OUTPUT_FILE"
|
||||
grep -o '"_\?[a-zA-Z0-9_]\+"' "$langfile" | \
|
||||
sort -u | \
|
||||
sed 's/^"//;s/"$//' >> "$OUTPUT_FILE"
|
||||
echo >> "$OUTPUT_FILE"
|
||||
done
|
||||
|
||||
echo "Migration file created at: $OUTPUT_FILE"
|
||||
echo "Please review and update the message IDs as needed."
|
@ -1,68 +0,0 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
# Script to migrate hardcoded messages to the message system
|
||||
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
SOURCE_DIR="$(dirname "$0")/.."
|
||||
LANG_FILE="${SOURCE_DIR}/include/qsgen2/lang/qsgen2.en"
|
||||
TEMP_FILE="${SOURCE_DIR}/.qsgen2.tmp"
|
||||
|
||||
# Create a backup of the original file
|
||||
backup_file() {
|
||||
local file="$1"
|
||||
local backup="${file}.bak.$(date +%s)"
|
||||
cp "$file" "$backup"
|
||||
echo "Created backup at: $backup"
|
||||
}
|
||||
|
||||
# Replace a message in the code
|
||||
replace_message() {
|
||||
local old_msg="$1"
|
||||
local new_key="$2"
|
||||
local file="$3"
|
||||
|
||||
# Escape special characters for sed
|
||||
local escaped_old=$(printf '%s\n' "$old_msg" | sed 's/[&/\^$*.]/\\&/g')
|
||||
local escaped_new="_msg i18n \"$new_key\""
|
||||
|
||||
# Handle messages with parameters
|
||||
if [[ "$old_msg" == *"%s"* ]]; then
|
||||
escaped_new="${escaped_new} \"\${1:-\"\"}\""
|
||||
fi
|
||||
|
||||
# Replace in file
|
||||
sed -i "s/_msg \(info\|warning\|error\|debug\|other\) \"$escaped_old\"/$escaped_new/g" "$file"
|
||||
}
|
||||
|
||||
# Process a single file
|
||||
process_file() {
|
||||
local file="$1"
|
||||
echo "Processing file: $file"
|
||||
|
||||
# Create a backup
|
||||
backup_file "$file"
|
||||
|
||||
# Replace messages
|
||||
while IFS= read -r line; do
|
||||
if [[ "$line" =~ ^([a-z.]+)[[:space:]]*=[[:space:]]*"([^"]+)" ]]; then
|
||||
local key="${match[1]}"
|
||||
local msg="${match[2]}"
|
||||
|
||||
# Skip comments and empty lines
|
||||
[[ "$key" == "#"* ]] && continue
|
||||
[[ -z "$key" ]] && continue
|
||||
|
||||
# Replace in file
|
||||
replace_message "$msg" "$key" "$file"
|
||||
fi
|
||||
done < "$LANG_FILE"
|
||||
}
|
||||
|
||||
# Find all shell scripts in the project
|
||||
find "$SOURCE_DIR" -type f \( -name "*.zsh" -o -name "*.sh" \) -not -path "*/.*" | while read -r file; do
|
||||
process_file "$file"
|
||||
done
|
||||
|
||||
echo "Migration complete. Please review the changes and test the application."
|
Loading…
x
Reference in New Issue
Block a user