localizing-shell-scripts-without bashisms, gettext or ...
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
localizing-shell-scripts-without bashisms, gettext or ...
Inspired by technosaurus' work on this, see
http://bashismal.blogspot.com/2011/10/l ... thout.html
I have been working on an example just a little bit larger then “hello world
http://bashismal.blogspot.com/2011/10/l ... thout.html
I have been working on an example just a little bit larger then “hello world
- Attachments
-
- t12s_translate.png
- That is not really Spanish
but it works - (23.25 KiB) Downloaded 2598 times
-
- t12s.gz
- klick to unzip it
and move it to ~/my-applications/bin
or /usr/sbin - (2.14 KiB) Downloaded 946 times
Last edited by L18L on Wed 16 Nov 2011, 20:17, edited 2 times in total.
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
ferro10n,
thanks for reporting
Answering your questions:
1: which puppy
This was made in wary 5.2.190 and should work in all puppies that have yad installed. Test this by entering yad in a console. If 'command not found then' then install yad from repo puppy-common.
2: which user
- To reproduce the screenshot you must run as root.
- To install askpass copy above script into /usr/sbin/askpass (you might copy the original askpass to askpass.orig before)
- To make a translation just start the script t12s. You will be asked for administrator's password if you are not root, and you will requested to enable utf8 if it is disabled.
To test the script completely you must do this as fido or spot.
I have run it in a real console (CTRL-ALT-F2, switch back to X by CTRL-ALT-F4):
login as root, then
su fido
pmount
This will ask for administrator's password using your translation.
Note,
Doing this I have found a small bug in permission of /dev/console.
/dev/console is writable by root only. That is wrong!
Fix it now by:
Looking forward to your translations
edited:
start with es only
I will have to make some changes that pt_BR will work too
thanks for reporting
Answering your questions:
1: which puppy
This was made in wary 5.2.190 and should work in all puppies that have yad installed. Test this by entering yad in a console. If 'command not found then' then install yad from repo puppy-common.
2: which user
- To reproduce the screenshot you must run as root.
- To install askpass copy above script into /usr/sbin/askpass (you might copy the original askpass to askpass.orig before)
- To make a translation just start the script t12s. You will be asked for administrator's password if you are not root, and you will requested to enable utf8 if it is disabled.
To test the script completely you must do this as fido or spot.
I have run it in a real console (CTRL-ALT-F2, switch back to X by CTRL-ALT-F4):
login as root, then
su fido
pmount
This will ask for administrator's password using your translation.
Note,
Doing this I have found a small bug in permission of /dev/console.
/dev/console is writable by root only. That is wrong!
Fix it now by:
Code: Select all
chgrp users /dev/console
chmod g+w /dev/console
edited:
start with es only
I will have to make some changes that pt_BR will work too
- Attachments
-
- t12s_start.png
- (20.46 KiB) Downloaded 2178 times
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
askpass
Just apply red marked changes to above /usr/sbin/askpass scriptL18L wrote:...
edited:
start with es only
I will have to make some changes that pt_BR will work too
#!/bin/sh
#Barry Kauler 2011, GPL3 (/usr/share/doc/legal)
#specified in /etc/sudoers or /etc/sudo.conf, gui-helper for sudo. (path compiled-in to my sudo PET)
#110513 display name of app that is requesting to run.
#111112 i18n by L18L using Technosaurus' method <smile>
#111114 expanding Technosaurus' method to enable en_AU, pt_BR,...
# /dev/console: write permission for users required !!!
#LANGPATH=/usr/share/locale/${LANG%_*}/askpass #111114
LANGPATH=/usr/share/locale/${LANG%.*}/askpass #111114
[ ! -f $LANGPATH ] && LANGPATH=/usr/share/locale/${LANG%_*}/askpass #111114
[ -f $LANGPATH ] && . $LANGPATH
PSALL="`ps`"
Is it easier?
As a conclusion, i do not think it is easier than using gettext.
gettext '.po' file can be edited by text editors. The original message is associated on the 'po' file.
But using the smert tools like poedit is more easier.
The way you discuss is the way MU did and now zigbert do.
There are some traps:
1. locale file path
MU placed the translation files at '/usr/share/locale/LANGAGE_CODE/LC_MESSAGES/APPNAME.mo'.
The place and the extention makes problem because they are not actually '.mo' files.
Zigbert places the translation files at /usr/local/APPNAME/locals with the file name as 'LANGUAGE_CODE:LANGUAGE_NAME'.
Therefore the translation files are here and there, so it takes a bit work to make a collection of NLS.
To place the translation files '/usr/share/locale/LANGAGE_CODE/APPNAME' is nice.
2. incomplete translations
The translation s are not always fully done.
When the programer add new messages, the old translations are lacking the messages.
If some messages are lacking, the program may fail.
Technosaulus proposes 'echo ${VAR:-default message}'. It is a solution but seems complax for me.
Another way is to make a default message file. But the program fails without the default message file.
I prefer to place the default messages at the top of the program. Like;
3. searching path of the translation file from the language code
it can be 'pl' and/or 'pl_BR'.
Here is a code using a default message file, '/usr/share/locale/C/APPNAME':
4. finding original messages
If the messages are in lines of the program code, it is a hard work to find the original messages to make the translations.
It is a hard work for the programmer if he offers a default messages as a file.
It is a hard work to replace the messages with making the variable names.
The xgettext automatically makes '.po' file with the message id's.
gettext '.po' file can be edited by text editors. The original message is associated on the 'po' file.
But using the smert tools like poedit is more easier.
The way you discuss is the way MU did and now zigbert do.
There are some traps:
1. locale file path
MU placed the translation files at '/usr/share/locale/LANGAGE_CODE/LC_MESSAGES/APPNAME.mo'.
The place and the extention makes problem because they are not actually '.mo' files.
Zigbert places the translation files at /usr/local/APPNAME/locals with the file name as 'LANGUAGE_CODE:LANGUAGE_NAME'.
Therefore the translation files are here and there, so it takes a bit work to make a collection of NLS.
To place the translation files '/usr/share/locale/LANGAGE_CODE/APPNAME' is nice.
2. incomplete translations
The translation s are not always fully done.
When the programer add new messages, the old translations are lacking the messages.
If some messages are lacking, the program may fail.
Technosaulus proposes 'echo ${VAR:-default message}'. It is a solution but seems complax for me.
Another way is to make a default message file. But the program fails without the default message file.
I prefer to place the default messages at the top of the program. Like;
Code: Select all
VAR="default message"
echo ${VAR}
it can be 'pl' and/or 'pl_BR'.
Here is a code using a default message file, '/usr/share/locale/C/APPNAME':
Code: Select all
LOCALEDIR=/usr/share/locale
LOCALEFILE=$(basename $0)
for D in C ${LANG%_*} ${LANG%.*}; do
F="$LOCALEDIR/$D/$LOCALEFILE"
[ -f "$F" ] && . "$F"
done
If the messages are in lines of the program code, it is a hard work to find the original messages to make the translations.
It is a hard work for the programmer if he offers a default messages as a file.
It is a hard work to replace the messages with making the variable names.
The xgettext automatically makes '.po' file with the message id's.
Downloads for Puppy Linux [url]http://shino.pos.to/linux/downloads.html[/url]
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
Re: Is it easier?
shinobar,
thanks for your input.
First:
- I like translations
- I like different methods
- I like to use the best available
- I like gettext. It is not out!
First time I was fascinated by speed see
http://murga-linux.com/puppy/viewtopic.php?t=70804 please
was technosaurus’ idea.
No. The original English message is shown.
Simplest example:
echo “$(gettext ’hello worls‘)
thanks for your input.
First:
- I like translations
- I like different methods
- I like to use the best available
- I like gettext. It is not out!
The goal is: faster than gettextshinobar wrote:As a conclusion, i do not think it is easier than using gettext.
First time I was fascinated by speed see
http://murga-linux.com/puppy/viewtopic.php?t=70804 please
The file '/usr/share/locale/LANGAGE_CODE/APPNAME' can be edited by text editors though without original message. My little GUI ‘t12s’ shows original message at translating. These are taken from a temporary file. No need to save it anywhere!shinobar wrote:gettext '.po' file can be edited by text editors. The original message is associated on the 'po' file.
Maybe. Let us wait if and how ferro10n will succeed translating to es and pt_BR.shinobar wrote:But using the smert tools like poedit is more easier.
Sorry, I do not understand this. But I will try to recomment further.shinobar wrote:The way you discuss is the way MU did and now zigbert do.
That is the very sad truth. [joke]better call them MU[/joke]shinobar wrote:There are some traps:
1. locale file path
MU placed the translation files at '/usr/share/locale/LANGAGE_CODE/LC_MESSAGES/APPNAME.mo'.
The place and the extention makes problem because they are not actually '.mo' files.
You know it is more than a bit.shinobar wrote:Zigbert places the translation files at /usr/local/APPNAME/locals with the file name as 'LANGUAGE_CODE:LANGUAGE_NAME'.
Therefore the translation files are here and there, so it takes a bit work to make a collection of NLS.
To place the translation files '/usr/share/locale/LANGAGE_CODE/APPNAME'shinobar wrote:To place the translation files '/usr/share/locale/LANGAGE_CODE/>APPNAME' is nice.
was technosaurus’ idea.
New messages always have to be translated new. Where is the problem? Just work to translate and update.shinobar wrote:2. incomplete translations
The translation s are not always fully done.
When the programer add new messages, the old translations are lacking the messages.
shinobar wrote:If some messages are lacking, the program may fail.
No. The original English message is shown.
Seemed the same to me at the beginning. But using it now it is more than just OK. We all need time to learn new things.shinobar wrote:Technosaulus proposes 'echo ${VAR:-default message}'. It is a solution but seems complax for me.
That is why a default message file is NOT needed, so no fail.shinobar wrote:Another way is to make a default message file. But the program fails without the default message file.
And I prefer to have the message there where it is used.shinobar wrote:I prefer to place the default messages at the top of the program. Like;Code: Select all
VAR="default message" echo ${VAR}
Simplest example:
echo “$(gettext ’hello worls‘)
Re: Is it easier?
How theL18L wrote:The goal is: faster than gettext
Code: Select all
echo “${_M_x:-hello world}
Downloads for Puppy Linux [url]http://shino.pos.to/linux/downloads.html[/url]
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
Re: Is it easier?
Technosauraus has explained how.shinobar wrote:...
How can it be faster without gettext?
I can only show that it is faster.
Code: Select all
# time echo "$(gettext 'hello world')"
hello world
real 0m0.014s
user 0m0.016s
sys 0m0.000s
# time echo “${_M_x:-hello world}
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
localizing-shell-scripts-without bashisms, gettext or ...
It is fast!
Another script /usr/sbin/alsawizard prepared translated and tested in 1 hour. Here it is:
edited
I have changed
"ALSA Wizard"
to
´ALSA Wizard´
in above script /usr/sbin/alsawizard
----
another edit
add the missing $ in line 33 please. Sorry
Must be:
LANGPATH=${TEXTDOMAINDIR}/${LANG%.*}/$TEXTDOMAIN
Another script /usr/sbin/alsawizard prepared translated and tested in 1 hour. Here it is:
------------------------------#!/bin/sh
#Lesser GPL licence v2 (/usr/share/doc/legal/lgpl-2.1.txt). 2007 www.puppylinux.com
#if [ "`/etc/rc.d/rc.alsa status | grep "not loaded"`" = "" ];then
# Xdialog --title "ALSA sound Wizard" --yesno "ALSA sound modules are currently loaded and active.\n
#If you answer Yes here, modules will be unloaded,\nand the Wizard will continue.\nAnswer No, Wizard will exit..." 0 0
# [ ! $? -eq 0 ] && exit
# /etc/rc.d/rc.alsa stop
#fi
#...above not necessary, alsaconf does it.
#100501 weird, nvidia xorg pet pkg seems to need the files created by busybox depmod,
#however alsaconf has been modified to run depmod-FULL. so, rerun busybox depmod after...
#110513 put up a preliminary dlg...
AUDIOICON='/usr/local/lib/X11/mini-icons/mini-speaker.xpm'
[ -f /usr/share/retrovol/images/working.png ] && AUDIOICON='/usr/share/retrovol/images/working.png'
#/usr/local/apps/ROX-Filer/ROX/MIME/audio.png
# <frame THREE: Reboot>
# <text><label>It is unusual, but presuming that you have booted Puppy for the first time, sometimes you have to shutdown (and create a session save-file) and reboot for sound to work. Various peripherals, especially modems, may have conflicting kernel sound driver requirements, which might not get sorted out until the second boot. If you played with the mixer settings but your sound is still not working, it is recommended that you still do not run the ALSA Wizard, instead choose to reboot (see menu). Recommend click 'EXIT' button below.</label></text>
# </frame>
#111116 i18n using _ M _ method L18L
# note, simple quote (') inside message is not allowed, used (´) instead
OUTPUT_CHARSET=UTF-8
export OUTPUT_CHARSET
TEXTDOMAINDIR=/usr/share/locale
TEXTDOMAIN=`basename $0`
LANGPATH=${TEXTDOMAINDIR}/${LANG%.*}/$TEXTDOMAIN
[ ! -f $LANGPATH ] && LANGPATH=${TEXTDOMAINDIR}/${LANG%_*}/$TEXTDOMAIN
[ -f $LANGPATH ] && . $LANGPATH
#
export ASKDIALOG="
<window title=\"${_M_1:-Sound Wizard}\" window_position=\"1\">
<vbox>
<text use-markup=\"true\"><label>\"<big>${_M_11:-Welcome to the Sound Wizard}</big>\"</label></text>
<text><label>${_M_12:-Presumably you are here because your sound does not work? If so, there are things that you should try before running the full ALSA Wizard}</label></text>
<frame ${_M_13:-ONE: Adjust levels}>
<hbox>
<text><label>${_M_14:-Often non-working sound is just a matter of unmuting (tick a checkbox) and/or bring up a level in the audio mixer. Click this button to run the mixer:}</label></text>
<vbox><button><input file>${AUDIOICON}</input><action>/usr/local/bin/defaultaudiomixer & </action></button></vbox>
</hbox>
</frame>
<frame ${_M_2:-TWO: Play test sound}>
<hbox>
<text><label>${_M_21:-Having adjusted the levels, click this button to play a test sound:}</label></text>
<vbox><button><input file>${AUDIOICON}</input><action>/usr/bin/aplay /usr/share/audio/2barks.au & </action></button></vbox>
</hbox>
<hbox>
<text><label>${_M_22:-On some hardware (very rare fortunately) sound plays but does not always stop! If your Puppy will not stop barking, click this button:}</label></text>
<vbox><button><input file>/usr/local/lib/X11/mini-icons/mini-stop.xpm</input><action>/usr/bin/killall aplay</action></button></vbox>
</hbox>
</frame>
<frame ${_M_3:-THREE: Multiple cards}>
<hbox>
<text><label>${_M_31:-Linux may have detected more than one audio interface or ´card´, and has set the wrong one as default. Run Kirk´s Multiple Sound Card Wizard to investigate this (note, a reboot is required for change to take effect):}</label></text>
<vbox><button><input file>${AUDIOICON}</input><action>/usr/bin/Multiple-Sound-Card-Wizard & </action></button></vbox>
</hbox>
</frame>
<text><label>${_M_4:-FOUR: After trying ONE, TWO, THREE above, sound still not working, click ´ALSA Wizard´ button:}</label></text>
<hbox>
<button>
<label>${_M_41:-ALSA Wizard}</label>
<action type=\"exit\">RUNALSA</action>
</button>
<button>
<label>${_M_42:-EXIT}</label>
<action type=\"exit\">EXIT</action>
</button>
</hbox>
</vbox>
</window>
"
RETVAL="`gtkdialog3 --program=ASKDIALOG 2>/dev/null`"
eval "$RETVAL"
[ "$EXIT" != "RUNALSA" ] && exit
#exec rxvt -e /usr/sbin/alsaconf
#rxvt -e /usr/sbin/alsaconf
#/usr/sbin/alsaconf #101015
rxvt -geometry 60x3 -bg orange -e /usr/sbin/alsaconf
#depmod
edited
I have changed
"ALSA Wizard"
to
´ALSA Wizard´
in above script /usr/sbin/alsawizard
----
another edit
add the missing $ in line 33 please. Sorry
Must be:
LANGPATH=${TEXTDOMAINDIR}/${LANG%.*}/$TEXTDOMAIN
- Attachments
-
- t12s.gz
- move it to
/usr/sbin/t12s (without .gz) - (6.72 KiB) Downloaded 899 times
-
- t12s_alsa.png
- translated alsawizard using t12s
- (51.48 KiB) Downloaded 2120 times
-
- alsawizard.gz
- move it to
/usr/share/locale/de/alsawizard (without .gz) - (1.21 KiB) Downloaded 845 times
Last edited by L18L on Thu 17 Nov 2011, 15:25, edited 2 times in total.
Re: Speed
Code: Select all
# time echo "$(gettext 'hello world')"
hello world
real 0m0.014s
user 0m0.016s
sys 0m0.000s
# time echo “${_M_x:-hello world}
Downloads for Puppy Linux [url]http://shino.pos.to/linux/downloads.html[/url]
Unfortunately I'm temporarily unable to full test these method. My computer seems to hate Wary 5.2! Especially trying to log in as fido
I was able to translate the askpass script, but when I run it I got a white window with a box and a button. I'm still willing to test, for it worked running Wary without save-file. Maybe there's something I didn't do properly.
From a beginner point of view, however, I have to agree with shinobar-san, this method is suitable for a bit more experienced people, and of course for those who aren't having a nightmare with a particular puppy version
I was able to translate the askpass script, but when I run it I got a white window with a box and a button. I'm still willing to test, for it worked running Wary without save-file. Maybe there's something I didn't do properly.
From a beginner point of view, however, I have to agree with shinobar-san, this method is suitable for a bit more experienced people, and of course for those who aren't having a nightmare with a particular puppy version
Last edited by ferro10n on Thu 17 Nov 2011, 13:44, edited 1 time in total.
A beginner Puppy Linux user
Intel(R) Celeron(R) CPU 2.13GHz 512MB
LiveCD user
Intel(R) Celeron(R) CPU 2.13GHz 512MB
LiveCD user
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
still willing to test
Thank you for reporting and for your good will to continueferro10n wrote:...
I was able to translate the askpass script, but when I run it I got a white window with a box and a button. I'm still willing to test, for it worked running Wary without save-file. Maybe there's something I didn't do properly.
..
I agree, askpass might be too complicated for a beginner.
Therefore I suggest:
- Take any recent puppy, install yad if it is not contained.
- copy above t12s (renamed from t12s.gz)
- copy above alsawizard (renamed from alsawizard.gz)
- Start t12s:
-- choose /usr/sbin/alsawizard in first dialog
-- enter es as language in second dialog
-- translate just 1 item and click execute button: you should see this item translated.
...and so on
-- enter pt_BR as language in second dialog
...and so on
Please report:
- which puppy version (if there is a problem I will install it for me to reproduce your problem)
- maybe a screenshot of translated alsawizard?
- send your translation (open /usr/local/share/es/alsawizard in geany then copy and paste into forum post)
- any problems you might have
Thanks in advance
L
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
using L18L's naming method, you can quickly autogenerate a template:
usage:
mki18n list of scripts
hmm, even though I used a bashism (read -d) it generates the entire template in less time than gettext takes to do a single translation
... it may be beneficial to change >$x.i18n to |sort -u >$x.i18n if you are planning to use a VAR multiple times
Code: Select all
#!/bin/bash
for x in $@ ; do
while read -d$ A || [ "$A" ]; do
case "$A" in
*{_M_*)B=_M${A##*_M};B=${B%%\}*}\";echo ${B//:-/=\"};;
esac
done < $x >$x.i18n
done
mki18n list of scripts
hmm, even though I used a bashism (read -d) it generates the entire template in less time than gettext takes to do a single translation
... it may be beneficial to change >$x.i18n to |sort -u >$x.i18n if you are planning to use a VAR multiple times
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
Re: still willing to test
Success this time around! Didn't have to change puppy version, it's Wary 5.2 running entirely from RAM. And I learned some German on the way Now testing pt-BRL18L wrote:Thank you for reporting and for your good will to continueferro10n wrote:...
I was able to translate the askpass script, but when I run it I got a white window with a box and a button. I'm still willing to test, for it worked running Wary without save-file. Maybe there's something I didn't do properly.
..
I agree, askpass might be too complicated for a beginner.
Therefore I suggest:
- Take any recent puppy, install yad if it is not contained.
- copy above t12s (renamed from t12s.gz)
- copy above alsawizard (renamed from alsawizard.gz)
- Start t12s:
-- choose /usr/sbin/alsawizard in first dialog
-- enter es as language in second dialog
-- translate just 1 item and click execute button: you should see this item translated.
...and so on
-- enter pt_BR as language in second dialog
...and so on
Please report:
- which puppy version (if there is a problem I will install it for me to reproduce your problem)
- maybe a screenshot of translated alsawizard?
- send your translation (open /usr/local/share/es/alsawizard in geany then copy and paste into forum post)
- any problems you might have
Spanish locale generated for ALSA Wizard:
Code: Select all
_M_1="Asistente de Sonido"
_M_11="Bienvenid@ al Asistente de Sonido"
_M_12="Seguramente usted está aquí porque no le funciona el sonido. Si es así, hay cosas que debe probar antes de iniciar el Asistente ALSA completo"
_M_13="UNO: Ajustar niveles"
_M_14="Los problemas de sonido suelen ser cosa de des-silenciar (marcar una casilla) y/o elevar un nivel en el mezclador de audio. Pulse este botón para iniciar el mezclador:"
_M_2="DOS: Reproducir un sonido de prueba"
_M_21="Ajustados los niveles, pulse este botón para reproducir un sonido de prueba:"
_M_22="En algún hardware (muy raro por suerte) ¡el sonido se reproduce pero no siempre se detiene! Si su Puppy no para de ladrar, pulse este botón:"
_M_3="TRES: Tarjetas múltiples"
_M_31="Linux puede detectar más de una interface o ´tarjeta´, y ha ajustado la equivocada como predeterminada. Inicie el Asistente de Tarjetas de Sonido Múltiples de Kirk para investigar (nota, requiere reiniciar para activar el cambio):"
_M_4="CUATRO: Después de probar UNO, DOS, TRES arriba, aún no funciona el sonido, pulse el botón ´Asistente ALSA´:"
_M_41="Asistente ALSA"
_M_42="SALIR"
- Attachments
-
- t12s-alsawizard-spanish-full-translation.png
- (182.13 KiB) Downloaded 863 times
-
- t12s-alsawizard-spanish-success.png
- (171.52 KiB) Downloaded 870 times
A beginner Puppy Linux user
Intel(R) Celeron(R) CPU 2.13GHz 512MB
LiveCD user
Intel(R) Celeron(R) CPU 2.13GHz 512MB
LiveCD user
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
Re: still willing to test
Don't be disappointed if something will not work with pt_BRferro10n wrote:...
Success this time around! Didn't have to change puppy version, it's Wary 5.2 running entirely from RAM. And I learned some German on the way Now testing pt-BR
...
Then this will be my fault.
Be patient with me, I am a slow learner.
Muchas gracias
Yeah, I forgot this isn't meant to work with other languages yet but despite I still saw the GUI in English, the locale for pt_BR was generated the same. I also noticed that when I was asked to select a locale it appeared as 'pt', not pt_BR. I can still test that part, and then Italian and that's all my knowledge. I'm glad to help wherever I can.
A beginner Puppy Linux user
Intel(R) Celeron(R) CPU 2.13GHz 512MB
LiveCD user
Intel(R) Celeron(R) CPU 2.13GHz 512MB
LiveCD user
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
autogenerating
Technosaurus,technosaurus wrote:using L18L's naming method, you can quickly autogenerate a template:usage:Code: Select all
#!/bin/bash for x in $@ ; do while read -d$ A || [ "$A" ]; do case "$A" in *{_M_*)B=_M${A##*_M};B=${B%%\}*}";echo ${B//:-/="};; esac done < $x >$x.i18n done
mki18n list of scripts
hmm, even though I used a bashism (read -d) it generates the entire template in less time than gettext takes to do a single translation
... it may be beneficial to change >$x.i18n to |sort -u >$x.i18n if you are planning to use a VAR multiple times
thank you, much appreciated
So this does confirm that we do not need to store English language files? They can be autogenerated very fast!
Having tried to really understand your mki18n I had to run it.
and "hacked" this variant:
# time mki18n askpass alsawizard#!/bin/bash
[ -f all_i18n ] && rm all_i18n # all in one
for x in $@ ; do
while read -d$ A || [ "$A" ]; do
case "$A" in
*{_M_*) B=_M${A##*_M};B=${B%%\}*}";echo ${x}:${B//:-/="};;
esac
done < $x |sort -u >$x.i18n >>all_i18n
done
real 0m0.213s
user 0m0.076s
sys 0m0.024s
#
Stuff for thoughts...
Naming method
(for the record) _M_
short, unique, restricted to letters and underscore, easy to grep
Location of language files
Maybe a directory of their own is better?
M under /usr/share/locale/<language>
LANGPATH would become 2 bytes longer
But anything inside is _M_ method
I am thinking that "all in one" can be helpful for our PuppyMaster.
GUI: search a word and get all phrases containing this word
and maybe use an existing phrase in a new script...
...if so then 1 translation less
Or using just one language file for all the basic Puppy scripts...
The locale is really only needed when using date, time, currency..
Not for "just language"
I know that you know it (reminding your example of de_JA )
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
Yes, this is Cutting Edgeferro10n wrote:Yeah, I forgot this isn't meant to work with other languages yet but despite I still saw the GUI in English, the locale for pt_BR was generated the same. I also noticed that when I was asked to select a locale it appeared as 'pt', not pt_BR. I can still test that part, and then Italian and that's all my knowledge. I'm glad to help wherever I can.
I am working on pt_BR...or generally enabling "regional variants"
I will make versions (not soon, maybe tomorrow) and post on page 1 (that is the way one should do it from beginning )
Thank you and good night (it is late here in Europe now)
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
I am posting from my Droid so the following syntax will be "off"
[ -f /.../$LANG/app ] && LOCALES=/.../$LANG/app ¦¦ [ -f /.../${LANG%%_*} ] && LOCALES=/.../${LANG%%_*}
. $LOCALES
Edit: haven't tested above because I was doing this:
replace trans.txt with your english file and tl=es with tl=??
where ?? is
[ -f /.../$LANG/app ] && LOCALES=/.../$LANG/app ¦¦ [ -f /.../${LANG%%_*} ] && LOCALES=/.../${LANG%%_*}
. $LOCALES
Edit: haven't tested above because I was doing this:
Code: Select all
curl -A firefox \
-F "file=@trans.txt;type=text/plain" \
-F "sl=en" \
-F "tl=es" \
http://translate.googleusercontent.com/translate_f | while read A || [ "$A" ]; do
case $A in
"<meta"*)continue;;
*"<pre>"*)echo ${A##*"<pre>"};;
*"</pre>"*)echo ${A%%"</pre>"*};;
*)echo $A;;
esac
done
where ?? is
- es>Spanish
yi>Yiddish
cy>Welsh
separator disabled>—
af>Afrikaans
sq>Albanian
ar>Arabic
hy>Armenian
az>Azerbaijani
eu>Basque
be>Belarusian
bn>Bengali
bg>Bulgarian
ca>Catalan
zh-CN>Chinese(Simplified)
zh-TW>Chinese(Traditional)
hr>Croatian
cs>Czech
da>Danish
nl>Dutch
en>English
et>Estonian
tl>Filipino
fi>Finnish
fr>French
gl>Galician
ka>Georgian
de>German
el>Greek
gu>Gujarati
ht>Haitian
Creole
iw>Hebrew
hi>Hindi
hu>Hungarian
is>Icelandic
id>Indonesian
ga>Irish
it>Italian
ja>Japanese
kn>Kannada
ko>Korean
la>Latin
lv>Latvian
lt>Lithuanian
mk>Macedonian
ms>Malay
mt>Maltese
no>Norwegian
fa>Persian
pl>Polish
pt>Portuguese
ro>Romanian
ru>Russian
sr>Serbian
sk>Slovak
sl>Slovenian
es>Spanish
sw>Swahili
sv>Swedish
ta>Tamil
te>Telugu
th>Thai
tr>Turkish
uk>Ukrainian
ur>Urdu
vi>Vietnamese
cy>Welsh
yi>Yiddish
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].