Added language translation for doom.
This commit is contained in:
parent
614094ad2b
commit
1452f5d926
@ -15,11 +15,13 @@ speak() {
|
||||
continue
|
||||
fi
|
||||
if [[ $startSpeech -eq 0 ]]; then
|
||||
echo "${line}" | {
|
||||
line=$(echo "${line}" |
|
||||
grep "${antiGrepStrings[@]}" |
|
||||
sed "${sedStrings[@]}" |
|
||||
spd-say -e ${spd_module} ${spd_pitch} ${spd_rate} ${spd_voice} ${spd_volume} -- > /dev/null 2>&1;
|
||||
}
|
||||
sed "${sedStrings[@]}")
|
||||
if [[ "$doomLanguage" != "en" ]]; then
|
||||
line=$(translate_text "$line")
|
||||
fi
|
||||
echo "${line}" | spd-say -e ${spd_module} ${spd_pitch} ${spd_rate} ${spd_voice} ${spd_volume} -- > /dev/null 2>&1;
|
||||
fi
|
||||
done
|
||||
}
|
||||
@ -72,6 +74,7 @@ doomGames=(
|
||||
|
||||
export antiGrepStrings=(
|
||||
'-E' '-v'
|
||||
'-e' '^$'
|
||||
'-e' '^[0-9]'
|
||||
'-e' '^P_StartScript:'
|
||||
'-e' '^(Facing|INTRO|MAP[0-9]+|^Unknown)'
|
||||
@ -80,7 +83,7 @@ export antiGrepStrings=(
|
||||
'-e' '^\[Toby Accessibility Mod\] (INTRO|READMe)([0-9]+).*'
|
||||
'-e' 'key card'
|
||||
'-e' '^New PDA Entry:'
|
||||
'-e' "^(As |Computer Voice:|Holy|I |I've|Monorail|Ugh|What|Where)"
|
||||
'-e' "^(As |Computer Voice:|Holy|I |I've|Monorail|Sector |Ugh|What|Where)"
|
||||
)
|
||||
|
||||
export sedStrings=('-E'
|
||||
@ -99,6 +102,41 @@ export sedStrings=('-E'
|
||||
'-e' 's/ ?\*+ ?//g'
|
||||
)
|
||||
|
||||
# Translation stuff
|
||||
doomLanguage="${doomLanguage:-en}"
|
||||
cache="${cache:-${XDG_CACHE_HOME:-$HOME/.cache}/linux-game-manager}"
|
||||
translationDB="${cache}/doom_${doomLanguage}.sqlite"
|
||||
|
||||
# Function to initialize SQLite database
|
||||
init_translation_db() {
|
||||
mkdir -p "$cache"
|
||||
if [[ ! -f "$translationDB" ]]; then
|
||||
sqlite3 "$translationDB" <<EOF
|
||||
CREATE TABLE translations (
|
||||
original TEXT PRIMARY KEY,
|
||||
translated TEXT
|
||||
);
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to translate text
|
||||
translate_text() {
|
||||
local text="$1"
|
||||
local translatedText
|
||||
# Check if translation exists in database
|
||||
translatedText=$(sqlite3 "$translationDB" "SELECT translated FROM translations WHERE original = ?;" "$text")
|
||||
if [[ -n "$translatedText" ]]; then
|
||||
echo "$translatedText"
|
||||
return 0
|
||||
fi
|
||||
translatedText=$(trans -b -t "$doomLanguage" "$text")
|
||||
# Store new translation in database
|
||||
sqlite3 "$translationDB" "INSERT INTO translations (original, translated) VALUES (?, ?);" "$text" "$translatedText"
|
||||
echo "$translatedText"
|
||||
}
|
||||
|
||||
|
||||
custom_game() {
|
||||
mapfile -t customGames < <(find "${0%/*}/TobyCustom/" -type f -iname '*.sh')
|
||||
declare -a customMenu
|
||||
@ -120,6 +158,11 @@ custom_game() {
|
||||
source "${customGame}"
|
||||
}
|
||||
|
||||
|
||||
if [[ "$doomLanguage" != "en" ]]; then
|
||||
init_translation_db
|
||||
fi
|
||||
|
||||
gameOption="$(dialog --backtitle "Select your Doom!" \
|
||||
--clear \
|
||||
--no-tags \
|
||||
|
@ -271,6 +271,7 @@ help() {
|
||||
echo "${configFile%/*}/settings.conf"
|
||||
echo "The syntax is variable=\"value\""
|
||||
echo
|
||||
echo "doomLanguage=\"en\" # 2 letter language code for translation."
|
||||
echo "ipfsGateway=\"https://gateway.pinata.cloud\" # Gateway to be used for ipfs downloads."
|
||||
echo "noCache=\"true\" # Do not keep downloaded items in the cache."
|
||||
echo "spd_module=\<module_name>\" # set speech-dispatcher module."
|
||||
@ -484,6 +485,7 @@ if [[ -r "${configFile%/*}/settings.conf" ]]; then
|
||||
source "${configFile%/*}/settings.conf"
|
||||
fi
|
||||
unset noCache
|
||||
export doomLanguage="${doomLanguage:-en}"
|
||||
export ipfsGateway="${ipfsGateway:-https://gateway.pinata.cloud}"
|
||||
export spd_module="${spd_module:+ -o ${spd_module}}"
|
||||
export spd_pitch="${spd_pitch:+ -p ${spd_pitch}}"
|
||||
|
Loading…
Reference in New Issue
Block a user