using yoshi to set language preferences
#1
I just ported a Java app called GoGrinder, which lets you explore Go (the board game) problems. In the documentation it says

To set GoGrinder to use a specific language, you can run it once using the defaultLanguage option:
java -jar GoGrinder.jar defaultLanguage=fr
GoGrinder will remember this setting in future sessions.
Currently supported languages and codes:
English - en
Czech - cz
German - de
Spanish - es
French - fr
Portuguese - pt
Russian - ru
Chinese - zh

So how do we write this into a little preferences applet? No problem. In the apps directory I created a yoshi file:

Code:
*.title = Change GoGrinder UI language
popup.type = popup
popup.label = New language?
popup.option1 = English
popup.option2 = Czech
popup.option3 = German
popup.option4 = Spanish
popup.option5 = French
popup.option6 = Portuguese
popup.option7 = Russian
popup.option8 = Chinese
popup.default = option1

and a bash script

Code:
#!/boot/system/bin/bash

## who am i? ##
_script="$(readlink -f ${BASH_SOURCE[0]})"

## Delete last component from $_script ##
_base="$(dirname $_script)"

cd $_base

if [ ! -f /bin/yoshi ]; then
    alert "This preference applet requires yoshi, available from the Fatelk repo"
    exit 1
else
    tmpfile=`finddir B_COMMON_TEMP_DIRECTORY`/gogrinderout
    yoshi ./gogrinder.yoshi>$tmpfile
    #we only need the first line for this one so no need for while IFS ...
    read response < $tmpfile
    case $response in
        popup=option1)
            lang=en
        ;;
        popup=option2)
            lang=cz
        ;;
        popup=option3)
            lang=de
        ;;
        popup=option4)
            lang=es
        ;;
        popup=option5)
            lang=fr
        ;;
        popup=option6)
            lang=pt
        ;;
        popup=option7)
            lang=ru
        ;;
        popup=option8)
            lang=zh
        ;;
    esac
    java -jar GoGrinder.jar defaultLanguage=$lang
    rm $tmpfile
fi

I thought of doing radiobuttons at first but you only get six of those to play with and I needed eight.

One case where this will fall flat is if yoshi is installed in ~/config instead of /boot/system. I'll see if I get around to fixing that - not fond of disjunctions in bash.

So now all I need to do is to stick an icon onto that script and link it to the Preferences section of the Deskbar. Total disk usage just over a kilobyte. I Heart yoshi!
Reply
#2
Nice!

replace

if [ ! -f /bin/yoshi ]; then

wirh

if [ ! -f /bin/yoshi ] && [ ! -f ~/config/bin/yoshi ]; then

Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)
Free Web Hosting