Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- VER="v1.01"
- #============================================================================== © 2016-2018 Martineau, v01.01
- #
- # Utility to query/manage Language Dictionaries
- #
- # Dictionary_MSG [ help | -h ]
- # { text_msg | msg_no [ language] } | { map { language } | reset }
- # Dictionary_MSG Yes
- # List all messages containing 'Yes' within the current/mapped Dictionary.
- # 124: Yes
- # 1509: Select [Yes] to enable filter that specify IP or port for control incoming and outgoing packets.
- # 1711: Selecting Yes allows multiple players in the LAN to play Starcraft at the same time.
- # <snip>
- # Dictionary_MSG Ja DE
- # List all messages containing 'Ja' in the German Dictionary
- # 73: Ich bin 16 Jahre oder älter.
- # 74: Bitte bestätigen Sie, dass Sie 16 Jahre oder älter sind.
- # 124: Ja
- # 299: Ihr Browser unterstützt kein JavaScript. Wahlen Sie einen Browser, der JavaScript unterstützt oder aktivieren Sie JavaScript zur Verwendung mit Ihrem RT-AC68U.
- # <snip>
- # Dictionary_MSG 1837
- # List message number '1837' within the current/mapped Dictionary.
- # 1837: IP address, server and hostname have not changed since the last update. If you want to update, please click [Yes].
- # Dictionary_MSG map JP
- # Replace the existing Language Dictionary with the Japanese Dictionary
- # Dictionary_MSG reset
- # Remove any Language Dictionary mapping
- # Print between line beginning with'#==' to first blank line inclusive
- ShowHelp() {
- awk '/^#==/{f=1} f{print; if (!NF) exit}' $0
- }
- ANSIColours () {
- cRESET="\e[0m";cBLA="\e[30m";cRED="\e[31m";cGRE="\e[32m";cYEL="\e[33m";cBLU="\e[34m";cMAG="\e[35m";cCYA="\e[36m";cGRA="\e[37m"
- cBGRA="\e[90m";cBRED="\e[91m";cBGRE="\e[92m";cBYEL="\e[93m";cBBLU="\e[94m";cBMAG="\e[95m";cBCYA="\e[96m";cBWHT="\e[97m"
- aBOLD="\e[1m";aDIM="\e[2m";aUNDER="\e[4m";aBLINK="\e[5m";aREVERSE="\e[7m"
- cRED_="\e[41m";cGRE_="\e[42m"
- }
- #=========================================================Main====================================================
- Main(){}
- ANSIColours
- # Help request ?
- if [ -z "$1" ] || [ "$1" == "help" ] || [ "$1" == "-h" ];then # Show help
- echo -e $cBWHT
- ShowHelp
- echo -en $cRESET
- exit 0
- fi
- # BR CZ DE ES FR IT KR NO RO SV TR UK
- # CN DA EN FI HU JP MS PL RU TH TW
- DICTIONARY=$(nvram get preferred_lang)
- # Was a dynamic language mapping/unmapping requested?
- case "$1" in
- "map") if [ ! -z "$2" ];then
- DICTIONARY=$(echo $2 | tr 'a-z' 'A-Z')
- if [ -f /www/$DICTIONARY.dict ];then
- # Map the desired Language Dictionary
- case $DICTIONARY in
- EN) TXT="English";;
- BR) TXT="Brazilian";;
- CN) TXT="Chinese";;
- CZ) TXT="Czech";;
- DA) TXT="Danish";;
- DE) TXT="German";;
- ES) TXT="Spanish";;
- FI) TXT="Finnish";;
- FR) TXT="French";;
- HU) TXT="Hungarian";;
- IT) TXT="Italian";;
- JP) TXT="Japanese";;
- KR) TXT="Korean";;
- MS) TXT="Malaysian";;
- NO) TXT="Norwegian";;
- PL) TXT="Polish";;
- RO) TXT="Romanian";;
- RU) TXT="Russian";;
- SV) TXT="Swedish";;
- TH) TXT="Thai";;
- TR) TXT="Turkish";;
- TW) TXT="Taiwanese";;
- UK) TXT="Ukrainian";;
- *) TXT="?";;
- esac
- echo -e "\n\t"${cBGRE}"Mapping" $TXT "Language Dictionary '/www/$DICTIONARY.dict' -> '/www/$(nvram get preferred_lang).dict'\n" $cBRED
- umount /www/$(nvram get preferred_lang).dict 2>/dev/null
- MSG="Setup is complete"
- MSGNO=$(awk -v pattern="${MSG}" '$0~pattern {print NR-1}' /www/EN.dict) # Get position in English
- MSGNO=$((MSGNO+1)) # Display as used in HTML index reference '<#123#>'
- mount -o bind /www/$DICTIONARY.dict /www/$(nvram get preferred_lang).dict
- echo -e $cBCYA"\t\t"$(df | grep /www/$(nvram get preferred_lang).dict)
- echo -e $cBMAG"\t\t"$(cat /www/$DICTIONARY.dict | awk NR==$MSGNO) # "Setup is complete" ->> translation
- echo -e "\n\t"${cBGRE}"Restarting httpd....."
- service restart_httpd
- echo -e $cRESET
- exit 0
- else
- echo -e "\a\n\t"${cBRED}"***ERROR Language Dictionary '/www/"$DICTIONARY".dict' not found!\n"$cRESET
- exit 99
- fi
- else
- echo -e "\a\n\t"${cBRED}"Missing arg2 Language Dictionary e.g. 'map FR' to map to French language\n"$cRESET
- exit 99
- fi
- ;;
- # Remove the mapping
- "reset") echo -e "\n\t"${cBGRE}"Removing Language Dictionary mapping for '/www/$(nvram get preferred_lang).dict'\n" $cBRED
- if [ ! -z "$(df | grep /www/$(nvram get preferred_lang).dict)" ];then
- umount /www/$(nvram get preferred_lang).dict
- #echo -en $cBCYA"\t\t"$(df | grep /www/$(nvram get preferred_lang).dict)
- MSG="Setup is complete"
- MSGNO=$(awk -v pattern="${MSG}" '$0~pattern {print NR-1}' /www/EN.dict) # Get position in English
- MSGNO=$((MSGNO+1)) # Display as used in HTML index reference '<#123#>'
- echo -e $cBMAG"\t\t"$(cat /www/$DICTIONARY.dict | awk NR==$MSGNO) # "Setup is complete" ->> translation
- echo -e "\n\t"${cBGRE}"Restarting httpd....."
- service restart_httpd
- else
- echo -e "\t\t"$cBYEL"*** No current Language Dictionary mapping for '/www/$(nvram get preferred_lang).dict'\n"
- fi
- echo -e $cRESET
- exit 0
- ;;
- esac
- # Dictionay query/enquire for a different language?
- if [ ! -z "$2" ];then
- DICTIONARY=$(echo $2 | tr 'a-z' 'A-Z')
- fi
- MSGNO=$1
- # Specific MSGNO requested.....
- if [ ! -z "$1" ] && [ "$(echo "$1" | grep -oE '^[0-9]+$')" ];then # Is a number provided
- if [ -f /www/$DICTIONARY.dict ];then
- if [ $(wc -l </www/$DICTIONARY.dict) -gt $MSGNO ];then
- MSGNO=$((MSGNO+1)) # Display as used in HTML index reference '<#123#>'
- echo -e "\n\t"${cBGRE}$MSGNO":\t"$(cat /www/$DICTIONARY.dict | awk NR==$MSGNO)"\n" $cRESET
- else
- echo -e "\n\t\a"$cBRED"MSGNO="$1" too large\n" $cRESET
- fi
- else
- echo -e "\n\t\a"$cBRED"Language dictionary '"$2".dict' not found...\tBR CZ DE ES FR IT KR NO RO SV TR UK CN DA EN FI HU JP MS PL RU TH TW\n" $cRESET
- fi
- else # Search for all matching text
- #grep -ni "$1" /www/$DICTIONARY.dict
- # Case match?
- if [ "Case" == "Yes" ];then
- awk -v pattern="${1}" '$0~pattern {print NR-1":\t"$0}' /www/$DICTIONARY.dict
- else
- if [ ! -z "$(awk -v pattern="${1}" 'tolower($0)~tolower(pattern) {print "\t"NR-1":\t"$0}' /www/$DICTIONARY.dict)" ];then
- echo -en "\n"$cMAG"\tMatching dictionary ('"$DICTIONARY.dict"') results for search string"${cBYEL}" '"$1"'\n\n" $cBCYA
- awk -v pattern="${1}" 'tolower($0)~tolower(pattern) {print "\t"NR-1":\t"$0}' /www/$DICTIONARY.dict
- else
- echo -e "\n\t\a"$cBRED"***No dictionay ('"$DICTIONARY.dict"') match for search string"${cBYEL}" '"$1"'" $cRESET
- fi
- fi
- echo -e $cRESET
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement