Page 1 of 7

Localizing scripts

Posted: Wed 04 Feb 2009, 14:48
by droope
Hi people,

I am going to bother you all again on this same issue, only that now in a separate thread.
The intention of this proyect, is, that before version 4.2 is launched, we can have all scripts fetch language files from a directory. (As done here)


Progress done:
Connect wizard (updated droope's corrected version)
Xwin
XorgWizard (Updated to Mu's corrected version)
Remasterpup2
Chooselocale
Bootmanager
Cups Shell
Petget.
Applications directory localized

Outdated
Updated 18/03/09. :)

Posted: Thu 05 Feb 2009, 16:50
by esmourguit
Bonjour,

I tried to localize xorgwizard how did Mu for a test. But it does not work.
As soon as I brought this:
#-- simple localization for scripts by MU
mo=xorgwizard.mo
lng=`echo $LANG | sed "s/\(..\).*/\1/"`
#echo $lng
. "/usr/share/locale/en/LC_MESSAGES/$mo"
if [ -f "/usr/share/locale/$lng/LC_MESSAGES/$mo" ];then
. "/usr/share/locale/$lng/LC_MESSAGES/$mo"
fi
The script would not work.
The beginnings are difficult.
Cordialement ;)

Posted: Thu 05 Feb 2009, 21:43
by droope
That's interesting, but, i don't think it will be that easy, i mean, you have to create the file first, and modify the Script's text variables to be looked for in the text file,


I GUESS... LOL.

Maybe we can try and do this, what do you think?

Yes!

Check this

Mu's version of some output:
<hbox spacing=\"10\">
<text use-markup=\"true\"><label>\"<b>$LINTERFACE</b>
$INTERFACE_INTERFACE\"</label></text>
<text use-markup=\"true\"><label>\"<b>$TYPE</b>
$INTERFACE_INTTYPE\"</label></text>
<text use-markup=\"true\"><label>\"<b>$MODULE</b>
$INTERFACE_FI_DRIVER\"</label></text>
<text use-markup=\"true\"><label>\"<b>$BUS</b>
$INTERFACE_BUS\"</label></text>
<text use-markup=\"true\"><label>\"<b>$DESCRIPTION</b>
$INTERFACE_INFO\"</label></text>
</hbox>


Idon'tknowwhos:
<hbox spacing=\"10\">
<text use-markup=\"true\"><label>\"<b>Interface</b>
$INTERFACE_INTERFACE\"</label></text>
<text use-markup=\"true\"><label>\"<b>Type</b>
$INTERFACE_INTTYPE\"</label></text>
<text use-markup=\"true\"><label>\"<b>Module</b>
$INTERFACE_FI_DRIVER\"</label></text>
<text use-markup=\"true\"><label>\"<b>Bus</b>
$INTERFACE_BUS\"</label></text>
<text use-markup=\"true\"><label>\"<b>Description</b>
$INTERFACE_INFO\"</label></text>
</hbox>
I would like to know if anyone knows of a program that'd let me to know the exact diferences between a file and another. It would save a lot of work for me.

Posted: Thu 05 Feb 2009, 22:26
by MU
The script would not work.
Not enough info ;)
If you run it in a console, you usually get error-messages.
You should paste them here.

Or start with a new script.

Code: Select all

#!/bin/bash
#-- simple localization for scripts by MU 
mo=mytest.mo 
lng=`echo $LANG | sed "s/\(..\).*/\1/"` 
#echo $lng 
. "/usr/share/locale/en/LC_MESSAGES/$mo" 
if [ -f "/usr/share/locale/$lng/LC_MESSAGES/$mo" ];then 
. "/usr/share/locale/$lng/LC_MESSAGES/$mo" 
fi

echo "${L_TEST}"
save it as "/usr/bin/mytest".
Make it executable:
chmod 755 /usr/bin/mytest

Then create 2 localized files:
/usr/share/locale/en/LC_MESSAGES/mytest.mo

Code: Select all

L_TEST="hello world!"
/usr/share/locale/fr/LC_MESSAGES/mytest.mo

Code: Select all

L_TEST="salut monde!"
The best will be to create them in leafpad.
To save them, choose "save as" and activate the charactercoding "UTF-8" in the "save as" dialog.

Then test it:
export LANG=en_US.utf8
mytest
export LANG=fr_FR.utf8
mytest


This should print:
hello world1
salut monde!


Mark

Posted: Thu 05 Feb 2009, 22:40
by MU
To compare files:
from Puppy 3:
gtkdiff-0.7.0
But it requires to install also Gtk 1.2 and Glib 1.2.

Maybe someone posted also a pet for a "diff" program, that has less dependencies.

Or use the console:
diff --help

Mark

Posted: Thu 05 Feb 2009, 23:10
by droope
MU wrote:
The script would not work.
Not enough info ;)
If you run it in a console, you usually get error-messages.
You should paste them here.

Or start with a new script.

Code: Select all

#!/bin/bash
#-- simple localization for scripts by MU 
mo=mytest.mo 
lng=`echo $LANG | sed "s/\(..\).*/\1/"` 
#echo $lng 
. "/usr/share/locale/en/LC_MESSAGES/$mo" 
if [ -f "/usr/share/locale/$lng/LC_MESSAGES/$mo" ];then 
. "/usr/share/locale/$lng/LC_MESSAGES/$mo" 
fi

echo "${L_TEST}"
save it as "/usr/bin/mytest".
Make it executable:
chmod 755 /usr/bin/mytest

Then create 2 localized files:
/usr/share/locale/en/LC_MESSAGES/mytest.mo

Code: Select all

L_TEST="hello world!"
/usr/share/locale/fr/LC_MESSAGES/mytest.mo

Code: Select all

L_TEST="salut monde!"
The best will be to create them in leafpad.
To save them, choose "save as" and activate the charactercoding "UTF-8" in the "save as" dialog.

Then test it:
export LANG=en_US.utf8
mytest
export LANG=fr_FR.utf8
mytest


This should print:
hello world1
salut monde!


Mark
Why are you using "L_TEST="salut monde!"" in the mo and mytest in the code? I'll try to do an example as you did.

Posted: Thu 05 Feb 2009, 23:20
by MU
mytest is the filename.

simplified:

Code: Select all

mo=mytest.mo
. "/usr/share/locale/en/LC_MESSAGES/$mo"
So the script will "source" (the . means to read a file) this languagefile:
/usr/share/locale/en/LC_MESSAGES/mytest.mo

In mytest.mo you define the variable L_TEST.
It will be good practice, to start localized variables with "L_", so that they can easily be found in a script. I did not do that in my first scripts, and later it was hard, to find them again.

Code: Select all

L_TEST="hello world!"
Then in your script, this variable is available too, as it was just "sourced" from the languagefile.
So you can print it now:

Code: Select all

echo "${L_TEST}"

Sidenote:
I use ${L_TEST} and not $L_TEST, as like this, it can be put in other words.
works not:
echo "$L_TESTis my first test."
works:
echo "${L_TEST}is my first test."

Mark

Posted: Fri 06 Feb 2009, 01:25
by droope
Thank you, this post has helped a lot.

I was thinking of using what you localized so as not to waste effort. So i thought I could compare the version you localized (before localization) and current version, but I need you to tell me exactly which version it is you translated, so as not to make the script any older by accident.

After you and the current developers of scripts answer, I should be able to start working. It shouldn't be a lot of work, i think.

DOn't know if the scripts have changed a lot, tho.

Posted: Fri 06 Feb 2009, 05:29
by HairyWill
to compare files on the command line use
diff file1 file2
puppy 4 contains the graphical diff program xfdiff in the utility menu, I usually start it from the prompt, ie
xfdiff file1 file2

Posted: Fri 06 Feb 2009, 07:49
by esmourguit
Bonjour,

Sorry for the inconvenience, but in fact it was missing the file /usr/share/locale/en/LC_MESSAGES/xorgwizard.mo. But not sure it was the issue.
Then it works.
Attached file xorgwizard4.2-localized and connectwizard-420loc for test and english and french files

Cordialement ;)

Posted: Fri 06 Feb 2009, 17:58
by droope
I am testing it, the only issue until now, it's that in the name of the window, when using EN locales, i get Assistant de conexion, or something similar.

I think the problem is in the .mo, tho.

I will try to localize it in french, and if it works, i'll translate it into spanish. :) As soon as we have all scripts set up on 4.2.

This should be included on 4.2, do you want me to tell whodo?

We should send him one or a few MP's :P So as not to lose localizated scripts again.

Edit: It's not working :( I chose fr_BR, is that correct?
Is it fully localized?

Posted: Sat 07 Feb 2009, 10:22
by esmourguit
Bonjour,
No it is not completely localized. I is just a test.
The french locale is fr_FR
But there is an issue in xorgwizard4.2-loc, line 777.
echo ' --no-collapse --title "Puppy Video Wizard" --ok-label "OK" --extra-label "TEST" --cancel-label "EXIT" --menu "$choosevideomode
it doesn't show the "choosevideomode" text. I don't know why. Maybe MU could help us.
Cordialement ;)

Posted: Sat 07 Feb 2009, 12:02
by MU
esmourguit wrote:Bonjour,
No it is not completely localized. I is just a test.
The french locale is fr_FR
But there is an issue in xorgwizard4.2-loc, line 777.
echo ' --no-collapse --title "Puppy Video Wizard" --ok-label "OK" --extra-label "TEST" --cancel-label "EXIT" --menu "$choosevideomode
it doesn't show the "choosevideomode" text. I don't know why. Maybe MU could help us.
Cordialement ;)
It seems, I had made the same mistake in Muppy with the old translated xorgwizard.
You might need this syntax:

Code: Select all

echo " --no-collapse --title "Puppy Video Wizard" --ok-label "OK" --extra-label "TEST" --cancel-label "EXIT" --menu "$choosevideomode
" >> /tmp/choosexmodedlg
The reason is, that a variable in single quotes is not resolved.
Try this in a console to see the difference:

Code: Select all

a=test
echo "$a"
echo '$a'
With replacing ' with ", also the " within that quote must be replaced with "

Mark

Posted: Sat 07 Feb 2009, 14:57
by esmourguit
Bonjour,
Thank you Mark for your help. Now it works.
Here the dotpet whith the french locale files for test.
Cordialement ;)

Posted: Sat 07 Feb 2009, 21:25
by maddox
Hi all,
Hope I posted this in the correct Topic.

It's really great news to see an effort to localize Puppy scripts.
If I may, I've got a few questions concerning gettext (po files), translation and puppy 4.2.

1: If Puppy is going to be completely translated, i.e. all scripts will use gettext and po files,
Could there be a problem, kernel or other wise, using so many extra variables for translation (a limit to the nber of variables used) and also could this impact Puppy's performance ?
... Some scripts use over a 100 translation variables and might call other scripts with extra translation variables.
performance drop i.e : .. number of translation variables and parsing the po file(s) to find the correct variable entry.

2: Has the community set-up any standard rules/guidelines to localise variables in a script : i.e preset variable names inside scripts or rules to define the variable names for translation.
.. There doesn't seem to be any real consistancy in the variable naming process.
frame -> $frame1 and in a completely different hbox/vbox $frame2 .. I can elaborate a bit more if needed.

3: What do you do about a Title, Label, Button or other forgotten bits that have no translation in a script ?
i.e. <button OK> or button cancel or Title ...dialup modem, MB/KB to Mo/Ko ..
Do we change the english script and submit the english modification.. but then, where to post the proposed change ?

4: Can All the text messages be translated with a po file in any script ? (except of course initrd.gz : language specific manual translation must be done)
i.e... echo "blabla" > /dev/console or echo "blabla" > 2&1
and indirectly, does X have to be running for gettext to work ?

Translation part:
5: Has anybody found an equivalent to yaf-splash ?
As it only correctly displays english characters, no matter what the encoding used.

6: Dialog doesn't seem to like accents -> shutdown/save script and others
The displayed box has holes punched in it using accents (incorrectly displayed) and the right edge is completely distorted.

7: From what I understand, the Puppy 4.2 will keep to UTF-8 encoding for scripts,
but then, we (French Toutou 4.1.2 ) had to encode some scripts into ISO-8859-1 for them to display the accents correctly.
MU kindly gave us a partial solution, his gxmessage and the switch "-encoding UTF-8", thanks MU.

The info I've found about UTF-8 is that english characters are 1 byte encoded and french characters are 2 byte encoded
Using the ISO-8859-1 encoding the french characters are 1 byte encoded.
This makes it difficult for us and probally others : we have to test each script and if necessary modify the script and adapt the encoding accordingly.

Sorry about the mostly questions post and the numerous edits.

Thanks in advance to all the worldwide puppy users.

Posted: Sun 08 Feb 2009, 21:08
by droope
Hi there maddox:

I don't think i have the moral authority to answer to that post :P And that is a really fancy way of saying, I don't know what to say. I guess there could be an issue with those, yes.


Ondevelop:

My script is acting weird, I've just started, but heres what I changed.
connectwizard.mo (es) wrote:$DIALUP="Internet by turtle..."
connectwizard 4.1.2 wrote:#-- simple localization for scripts by MU
mo=conectwizard.mo
lng=`echo $LANG | sed "s/\(..\).*/\1/"`
#echo $lng
. "/usr/share/locale/en/LC_MESSAGES/$mo"
if [ -f "/usr/share/locale/$lng/LC_MESSAGES/$mo" ];then
. "/usr/share/locale/$lng/LC_MESSAGES/$mo"
fi
And:
the same file, later on wrote: <label>${DIALUP}</label>

And the weird behaviours are:

number 1: When I click on the script with rox, nothing happens. When I open a console there and run it, it works :/

Number 2: The text is not changing, I am using ES_es locales, and the mo file is located in /usr/share/locales/es/LC_MESSAGES/ ... :/


Could I get a hand? Sorry for all the newbieing. :) Thanks


EDIT:

DOH!!! (homer style) I had localized a part of the script that was comented out. :P Now it still won't work, I've edited my post to correct the horror i had done.

Posted: Sun 08 Feb 2009, 22:10
by maddox
Hi droope,
For the Rox problem, your file is probally not executable, right-click on the file in Rox and choose File -> Properties ...Tick all 3 Execute boxes.
An executable script needs this 1st line for it to run : #!/bin/bash
If your script doesn't use any X boxes (yaf-splash, xmessage/gxmessage), the console will just flash by, no time to see any messages.
But if you want to see what's happening, you'll have to run it from a console anyway.

For the locale problem: normally locales are like this -> fr_FR ... lowercase underline UPPERCASE
so I suppose yours should be -> es_ES and not ES_es

connectwizard.mo (es) wrote:
$DIALUP="Internet by turtle..."
Internet by turtle... -> this should be in your language, it's the translation
check your po file

Hope this helps you.

Posted: Sun 08 Feb 2009, 23:20
by MU
droope wrote:My script is acting weird, I've just started, but heres what I changed.
connectwizard.mo (es) wrote:$DIALUP="Internet by turtle..."
Must be:

Code: Select all

DIALUP="Internet by turtle..."
When you assign a value to a variable, it must not have the leading $.
Mark

Posted: Sun 08 Feb 2009, 23:37
by MU
maddox,
1: If Puppy is going to be completely translated, i.e. all scripts will use gettext and po files,
Could there be a problem, kernel or other wise, using so many extra variables for translation (a limit to the nber of variables used) and also could this impact Puppy's performance ?
In Muppy I had no problems yet concerning this.
2: Has the community set-up any standard rules/guidelines to localise variables in a script : i.e preset variable names inside scripts or rules to define the variable names for translation.
No.
However it does not matter, as every program uses an own mo file, there is no "central" mo used by more than one script.

The process is basically, that one starts to localize a script.
He will first create the english mo file.
It then has all the required variables, that other translators can use for translated mo files.
3: What do you do about a Title, Label, Button or other forgotten bits that have no translation in a script ?
i.e. <button OK> or button cancel or Title ...dialup modem, MB/KB to Mo/Ko ..
Dialog itself has a mo file to translate "yes", "no" and similar.
But I think it is not included in Puppy.
I attach a "full" dialog with translations.
For custom texts, that are used later in a condition, it is a problem though.
Here we had to keep the english text, or rewrite the conditions somehow.
This would require a non-trivial rewrite of the script :?
4: Can All the text messages be translated with a po file in any script ? (except of course initrd.gz : language specific manual translation must be done)
i.e... echo "blabla" > /dev/console or echo "blabla" > 2&1
and indirectly, does X have to be running for gettext to work ?
My simple approach does not require gettext :)
Translation part:
5: Has anybody found an equivalent to yaf-splash ?
As it only correctly displays english characters, no matter what the encoding used.
In Muppy and Newyearspup I use a wrapperscript that invoques gxmessage:

Code: Select all

#!/bin/bash

XMESSAGE="gxmessage -encoding UTF-8"

text=`echo $@ | sed -e "s/.*-text \(.*\)/\1/"`
#echo "$text"

a=`echo $@ | sed -e "s/-bg pale /-bg /" -e "s/-placement [^ ]* //" -e "s/-outline [^ ]* //" -e "s/-margin [^ ]* //" -e "s/-text .*//"`

#echo $a

exec $XMESSAGE -center -buttons "" -borderless $a "$text"
It covers most, but not all the usage of yaf-splash in Puppy.
So far, enough to use it in those pupletts.
6: Dialog doesn't seem to like accents -> shutdown/save script and others
The displayed box has holes punched in it using accents (incorrectly displayed) and the right edge is completely distorted.
In Muppy, I used a newer version from Slackware.
I attach it, please try that one.
I did not check it in Puppy itself, so I hope it has no missing dependencies.
Backup your savefile first!
7: UTF-8 in general:
For serious localization, Puppy needs to use UTF-8.
The newer kernels activate utf-8 by default.
In Muppy 0084c4 that worked fine.
For older kernels, ugly backports had to be written, to use a mix of ISO and UTF-8.
I know no simple solution for that.
But this basically just concerns initrd.gz (init), and one or 2 other files (I think /etc/rc.d/rc.shutdown, as it runs with dialog in console).

In the Muppy-buildsystem, I added a condition:
for new kernels, copy a UTF encoded file, for old ones, a ISO encoded file.

Mark

Posted: Mon 09 Feb 2009, 02:56
by maddox
Hi MU,
Thanks for all that VERY usefull info, it will be relayed back into Toutou and put into practice.
Will keep you informed about your yaf-splash and Dialog work-arounds ;)

The complete UTF-8 way (KERNEL and UTF-8 compatible programs) is really the right road from now on, just look at the numerous Puppy translations available.
- Most of the other (non english) Puppy translations had to recompile the kernel with UTF-8 support for simple things like fat/vfat bindings and other hitches :
.. nls_cp437 (english only) and nls_iso8859-1 (doesn't include all world languages) .. Then modify the "init" script accordingly and add the nls_utf8 file.

UTF-8 might slow Puppy down as characters could be multi-byte encoded, depends on the language used.
But it will have the added advantage of easier Puppy translation to many foreign languages (no need to change the script encoding)

Thanks for the positive info about the po/mo question. (nber 1)