Page 2 of 2

Re: "Welcome, this is the first time you run ....."

Posted: Sat 15 Feb 2014, 21:13
by L18L
L18L wrote:Pointers to actual code will always be in 2nd post of this thread besides a 32bit executable.
...done

Changes:
gray outed button
larger screen (640x480) for language choice

Posted: Mon 03 Mar 2014, 10:35
by L18L
Some other languages would be nice :)

Posted: Wed 05 Mar 2014, 18:26
by vicmz
Portuguese (from mariojrmatos' langpack)
Italian (my Italian is somewhat correct, but a native speaker's check would be great).

Posted: Fri 28 Mar 2014, 18:40
by L18L
vicmz wrote:Portuguese (from mariojrmatos' langpack)
Italian (my Italian is somewhat correct, but a native speaker's check would be great).
I did not forget you.
Thank you very much.

...and here is the 100-liner that created the image

Code: Select all

#!/bin/sh
# let user choose a language from installed mo files for app
# was implemented in welcome1stboot.bac
# but as shell script here now
# L18L March 2014 GPL
#

version=0.1

die() { echo $1; exit 1;}

usage()
{
 echo "
 usage: $0 textdomain [ app ]
 
 app only needed if different from textdomain
 choose a language from available textdomains
 app will be launched in chosen language
 
 -h this help 
 -v version
 " 	
}

[ $1 = '-h' ] && { usage; exit 0; }
[ $1 = '-v' ] && { echo ${0##*/} version $version; exit 0; }

textdomain=$1 && [ $textdomain ] || die "which textdomain?"
app=$2 && [ "$app" ] || app=$textdomain

# some files
all_language_names=/usr/share/i18n/lang_names
[ -f $all_language_names ] || all_language_names=lang_names
[ -f $all_language_names ] || die "missing file lang_names, exiting"
these_languages=/dev/shm/language_names
chosen_lang=/dev/shm/chosen_lang_code

# English plus all other available languages for textdomain
langs="en `find /usr/share/locale/*/LC_MESSAGES/${textdomain}.mo|cut -d'/' -f5`"
num_languages="`echo $langs | wc -w`"
echo -n '' > $these_languages
for x in $langs;do echo "`grep ^$x $all_language_names`">>$these_languages;done

# GUI ========================================================================
num_cols=2 # number of columns
[ $num_languages -gt 4 ] && num_cols=3
[ $num_languages -gt 6 ] && num_cols=4

choose_language='
<window title="'$textdomain'" icon-name="gtk-preferences" window-position="1">
<vbox space-expand="true" space-fill="true">
 <vbox spacing="10" space-expand="true" space-fill="true">
 <frame ? ? ?>
  <hbox spacing="10" homogeneous="true" space-expand="true" space-fill="true">
'
x=0
col=0
while [ $x -lt $num_languages ] ; do 
 x=$(($x + 1))
 col=$(($col + 1))
 read language_name             #ex: de:Deutsch  
 lang_code=${language_name%:*}  #ex: de
 lang_name=${language_name#*:} #ex: Deutsch
 choose_language=${choose_language}'
    <button image-position="2">
     <label>"'$lang_name'"</label>
     '"`/usr/lib/gtkdialog/xml_button-icon reboot.svg huge`"'
     <action>echo '$lang_code' > chosen_lang</action>
     <action>exit:exit</action>
    </button>'
 if [ $col -ge $num_cols ]; then
  col=0
  choose_language=${choose_language}'
   </hbox>
   <hbox spacing="10" homogeneous="true" space-expand="true" space-fill="true">'
 fi
done < $these_languages
choose_language=${choose_language}'
   </hbox>
  </frame>
 </vbox>
</vbox>
</window>'
# /GUI ========================================================================

export choose_language
eval `gtkdialog -p choose_language`
chosen_lang_code=`cat chosen_lang` 
#echo chosen_lang_code=`cat chosen_lang`   #example: "nl"

#prepend chosen_lang_code to envirinment variable LANGUAGE
#echo LANGUAGE=$LANGUAGE                   #example: "fr:de:"
[ "$LANGUAGE" ] && LANGUAGE=":${LANGUAGE}" #example: ":fr:de:"
LANGUAGE="${chosen_lang_code}${LANGUAGE}"  #example: "nl:fr:de:"
export LANGUAGE

$app & #launch application
exit 0 #end

Posted: Tue 01 Apr 2014, 12:35
by L18L
Script in previous post works in slacko only I think.

Script development continued in cutting edge.
There is a pet you can use to run any application in any installed language. that is use it for welcome1stboot or geany or (even) xwin 8)

Should work with Brazilian and Chinese tooo...