Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 02 Sep 2014, 18:04
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
internationalization of initrd messages at bootup
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 2 of 4 [52 Posts]   Goto page: Previous 1, 2, 3, 4 Next
Author Message
L18L

Joined: 19 Jun 2010
Posts: 2505
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Fri 21 Oct 2011, 06:17    Post subject: internationalization of initrd messages at bootup
Subject description: ${LANG:0:2}
 

technosaurus wrote:
i had done it like this:

[ -e /etc/locale/${LANG}/init ] && . /etc/locale/${LANG}/init

but realized that sometimes it may be something like de_DE (thus the case statement)

but now that you mentioned it, it could be
Code:

[ -e /etc/locale/${LANG:0:2}/init ] && . /etc/locale/${LANG:0:2}/init

replacing ${LANG:0:2}
by
`echo $LANG | cut -d '_' -f 1` (or equivalent in pure shell)
would serve 3-letters coded languages too, they exist Smile
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2505
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Fri 21 Oct 2011, 06:55    Post subject: internationalization of initrd messages at bootup
Subject description: pkeys and/or plang
 

BarryK wrote:
Hi guys,
This is interesting stuff. I'm a bit pre-occupied right now, but intend to come back and read this thread properly later.

One quick question. L18L, I see that you propose "plang=de", but Puppy already supports "pkeys=de" -- couldn't we just have the one, to simplify things? Perhaps "plang=de" could also imply keyboard layout is "de". Or, maybe they do need to remain separate.


Quick answer
plang is just the language to start with (locale not needed)
or better call it: planguage to not confuse with LANG

I am using pkeys=de-latin1 (simple de does not work for me)
Sometimes a user has to use a keyboard of another language...
And sometimes a user might want to use another language with the same keyboard...

I have been thinking about why pkeys is necessary at all at booting.
choosing one of the save files? just a number
What else?
Entering password in case of encrypted save file !
Other cases? I don't know.

Omitting pkeys as boot parameter we had just to switch keyboard layout temporarily to default en_US when asking for password...
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2505
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Fri 21 Oct 2011, 08:45    Post subject: internationalization of initrd messages at bootup
Subject description: proof of concept
 

Here is what I have changed in initrd to enable translation of messages

Note, the most important thing for me was to find consolefonts.

Code:
 [ $plang = "el" ] && zcat /lib/consolefonts/LatGrkCyr-8x16.psfu.gz   | loadfont # All European languages
[ $plang != "el" ] && zcat /lib/consolefonts/LatArCyrHeb-8x16.psfu.gz | loadfont # no Greek
#translate rest of splitted script (= init2) to boot param plang #L18L
[ $plang -a -f /boot_msg/${plang} ] &&  mv /init2 /trans && sed -f /boot_msg/${plang} /trans > /init2 && rm /trans
. /init2


Start it from grub with plang=el (Greek)
It is not "all Greek Very Happy "
or
plang=ru (Russian)
It is not "all Cyrillic Very Happy "
or
plang=de (German)

edited:
bug, use next version 8 posts down please
puppy_init_i18n.tar.gz
Description  only for people who know how to edit their initrd.gz
gz

 Download 
Filename  puppy_init_i18n.tar.gz 
Filesize  36.96 KB 
Downloaded  266 Time(s) 

Last edited by L18L on Mon 24 Oct 2011, 12:32; edited 1 time in total
Back to top
View user's profile Send private message 
Moose On The Loose


Joined: 24 Feb 2011
Posts: 515

PostPosted: Fri 21 Oct 2011, 10:45    Post subject: Further on the script optimization
Subject description: We can make the action happen after the case
 

[quote="technosaurus"
Code:

[ -e /etc/locale/${LANG:0:2}/init ] && . /etc/locale/${LANG:0:2}/init
[/quote]

Since you need the 1st two characters in more than one place, it may be worth doing that once at the top and making a variable of just the 1st two.

Now to the main subject of this:

On the case for doing the fonts, I think it would be best if the case statement only assigned variables and then the real action happen afterwards. This way, a check that it worked or didn't can be done and perhaps the user warned.

It also looked like nearly the same code is repeated many times. There should be some way to reduce this down.
Back to top
View user's profile Send private message 
Moose On The Loose


Joined: 24 Feb 2011
Posts: 515

PostPosted: Fri 21 Oct 2011, 11:02    Post subject: Re: internationalization of initrd messages at bootup
Subject description: ${LANG:0:2}
 

L18L wrote:

`echo $LANG | cut -d '_' -f 1` (or equivalent in pure shell)
would serve 3-letters coded languages too, they exist Smile


Code:

FIRST=${LANG/_*/}


If they then add a 4 letter language, it will work
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2505
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Fri 21 Oct 2011, 13:42    Post subject: Re: Further on the script optimization
Subject description: We can make the action happen after the case
 

Moose On The Loose wrote:

On the case for doing the fonts, I think it would be best if the case statement only assigned variables and then the real action happen afterwards. This way, a check that it worked or didn't can be done and perhaps the user warned.

It appears to me you did not run i18n in console_i18n_demo so you doubt about it. I cannot see any reason why a simple loadfont should not work Cool

Moose On The Loose wrote:

It also looked like nearly the same code is repeated many times. There should be some way to reduce this down.

Sorry, which code? Could you elaborate please?

Moose On The Loose wrote:
Code:
FIRST=${LANG/_*/}

Very nice, thank you Smile
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4348

PostPosted: Fri 21 Oct 2011, 22:10    Post subject: Re: Further on the script optimization
Subject description: We can make the action happen after the case
 

L18L wrote:

Moose On The Loose wrote:
Code:
FIRST=${LANG/_*/}

Very nice, thank you Smile

${LANG%_*} is more portable (though not as portable as ${LANG:0:2}, Do any of these mystery locales not have unique first 2 chars?)

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4348

PostPosted: Fri 21 Oct 2011, 22:21    Post subject: Re: Further on the script optimization
Subject description: We can make the action happen after the case
 

Moose On The Loose wrote:

On the case for doing the fonts, I think it would be best if the case statement only assigned variables and then the real action happen afterwards. This way, a check that it worked or didn't can be done and perhaps the user warned.

If you ever want to tell the user if something fails during boot, you can do a couple of things:
some_command 2>/dev/console
or
some_command 2>/dev/null || echo $ERRORMESSAGE >/dev/console

the first case uses command's error message (may not be localized)
the second outputs a localizable error message IFF the command fails

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
Moose On The Loose


Joined: 24 Feb 2011
Posts: 515

PostPosted: Fri 21 Oct 2011, 22:28    Post subject: Re: Further on the script optimization
Subject description: We can make the action happen after the case
 

L18L wrote:

It appears to me you did not run i18n in console_i18n_demo so you doubt about it. I cannot see any reason why a simple loadfont should not work Cool

I didn't run it. However "should not work" is very like "I should be rich and good looking". Somehow the universe conspires to make things that "should be" happen to be "It aint"

Quote:

Moose On The Loose wrote:

It also looked like nearly the same code is repeated many times. There should be some way to reduce this down.

Sorry, which code? Could you elaborate please?


You have the same calls in each case. It is only the font that gets loaded that varies. It seems like there should be a way to make it so you use one call with the arguments changed magically.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4348

PostPosted: Fri 21 Oct 2011, 22:57    Post subject: Re: Further on the script optimization
Subject description: We can make the action happen after the case
 

Moose On The Loose wrote:

You have the same calls in each case. It is only the font that gets loaded that varies. It seems like there should be a way to make it so you use one call with the arguments changed magically.

you could, but it would be dumb, because it is inside a case statement (only one is actually executed, but it is a little disconcerting to see until you get used to it)

if there were more than 10 it may be useful to set up a function, but the function itself requires code and has its own overhead ... perhaps when we get the Klingon, Vulcan and various Middle Earth translations, it will be worth it though

if you were to set a variable and then exec the command afterwards, the variable setting will be "duplicate" code ... sure if you choose a short/meaningless variable name you can save the difference in bytes between the actual text of the variable and command, but then it ends up allocating RAM (which in an initramfs comes from the same place)

when the initrd gets compressed, duplicates of text are practically eliminated size-wize, so worrying about a few extra imaginary bytes at the expense of readability is pointless

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2505
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Sun 23 Oct 2011, 14:23    Post subject: internationalization of initrd messages at bootup
Subject description: bugfix
 

Thanks to the comments of MooseOnTheLoose and technosaurus (don't let us forget sc0tman's slovio Smile ) here is now a version including a little menu.

The names of the languages are in 1st line of translation file.
Example for Russian:
Code:
s#English#pусский#


the translation files for languages other than German are containing just some phrases for demonstration purposes only

1 problem remaining: consolefont for Arab and Hebrew
In my example script i18n both fonts were set by setfont
setfont is not available init initrd
So I have been using loadfont
But loadfont does NOT load LatArCyrHeb-16.psfu.gz

To enable Arabic and Hebrew languages busybox version in initrd must support setfont. Help me if you can... I cann't


Here the new init script

Code:
#!/bin/sh
#(c) Copyright 2007 Barry Kauler, www.puppylinux.com
#2007 GPL licence v2 (/usr/share/doc/legal/gpl-2.0.txt)
#Aug 2007, init script in initramfs, for puppy v2.20, Sept: v3.00, Oct: v3.01
..
comments cut off
...
#/bin/hotplug2stdout_notimeout > /tmp/pup_event_uevents_initrd &

# i18n
zcat /lib/consolefonts/LatGrkCyr-8x16.psfu.gz | loadfont # All European languages; new default ?!

# I assume setfont instead of loadfont would work but it is not supported in this busybox of initrd
#case $plang in
## ar|iw)    zcat /lib/consolefonts/LatArCyrHeb-16.psfu.gz | loadfont   ;; # no Greek # not working
#  ar|iw) setfont /lib/consolefonts/LatArCyrHeb-16.psfu.gz -C /dev/tty1 ;; # no Greek # setfont needed?
#esac

if [ "$plang" = "" ]; then # plang could be set in menu.lst or elsewhere...
 # a litte menu to choose language from translation files
 cd boot_msg
 x=-1; nmax=`ls | wc -w`
 while [ $x -lt 0 -o $x -gt $nmax 2>/dev/null ]; do
  clear; echo "
 "
  n=0; echo "  ${n} <--- "English
  for lang in `ls`; do
   n=`expr $n + 1`
   read LINE <$lang
   LINE=`echo $LINE | cut -d '#' -f 3`
   echo "  ${n} <--- "$LINE
  done
  echo -n "
? "
  read x
  x=`echo $x | sed -e s/[^0-9]//g`
 done
 # now find the directory...it is the x-th word of ls
 dir=`ls`
 plang=`echo $dir | cut -d ' ' -f $x 2>/dev/null`
 cd - >/dev/null
# end of menu
fi

#translate rest of splitted script (= init2) to boot param plang or chosen in above menu
[ $plang -a -f /boot_msg/${plang} ] &&  mv /init2 /trans && sed -f /boot_msg/${plang} /trans > /init2 && rm /trans
. /init2

# end of i18n


The screenshot is simulated in X.
It works in real boot process with another font of course.
I am using it in wary5.2
initrd_boot_menu.png
 Description   -
 Filesize   2.65 KB
 Viewed   1003 Time(s)

initrd_boot_menu.png

puppy_init_i18n_menu.tar.gz
Description  to be merged into initrd
gz

 Download 
Filename  puppy_init_i18n_menu.tar.gz 
Filesize  37.7 KB 
Downloaded  271 Time(s) 
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2505
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Wed 26 Oct 2011, 09:15    Post subject: Re: internationalization of initrd messages at bootup
Subject description: GUI to edit initrd.gz
 

L18L wrote:
I am using it in wary5.2

I am using it in slacko52 now.

GUI to edit initrd.gz
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2505
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Tue 13 Dec 2011, 09:55    Post subject: multi-byte strings
Subject description: arrow-down
 

multi-byte char ↓ (arrow down) in initrd Very Happy

s#Type a number to choose which personal file to use:# Tipp eine ...
arrow_down_in_action.jpg
 Description   
 Filesize   13.61 KB
 Viewed   685 Time(s)

arrow_down_in_action.jpg

Back to top
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2240

PostPosted: Tue 13 Dec 2011, 12:27    Post subject:  

They should remain separate -I have a 'de' keyboard but use English and I imagine there are others that do similar.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4348

PostPosted: Tue 13 Dec 2011, 12:46    Post subject:  

also you can use read -t <seconds>

but here is are a couple little chunks

Code:
cd $DIR
i=0; for x in *; do i=$(($i+1)) && echo "( $i ) $x"; done

read -t 10 x
echo * |awk '{print $'${x:-$defaultvalue}'}'

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 2 of 4 [52 Posts]   Goto page: Previous 1, 2, 3, 4 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Cutting edge
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1268s ][ Queries: 12 (0.0263s) ][ GZIP on ]