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 Fri 19 Dec 2014, 11:57
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
localizing-shell-scripts-without bashisms, gettext or ...
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 2 of 5 [63 Posts]   Goto page: Previous 1, 2, 3, 4, 5 Next
Author Message
L18L

Joined: 19 Jun 2010
Posts: 2610
Location: www.eussenheim.de/

PostPosted: Thu 17 Nov 2011, 11:44    Post subject: Re: still willing to test
Subject description: alsawizard
 

ferro10n 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 Laughing Now testing pt-BR
...


Don't be disappointed if something will not work with pt_BR
Then this will be my fault.
Be patient with me, I am a slow learner.

Muchas gracias Very Happy Very Happy Very Happy
Back to top
View user's profile Send private message 
ferro10n

Joined: 15 Jun 2011
Posts: 106

PostPosted: Thu 17 Nov 2011, 13:57    Post subject:  

Yeah, I forgot this isn't meant to work with other languages yet Laughing 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. Very Happy
_________________
A beginner Puppy Linux user
Intel(R) Celeron(R) CPU 2.13GHz 512MB
LiveCD user
Back to top
View user's profile Send private message Visit poster's website 
L18L

Joined: 19 Jun 2010
Posts: 2610
Location: www.eussenheim.de/

PostPosted: Thu 17 Nov 2011, 15:53    Post subject: autogenerating  

technosaurus wrote:
using L18L's naming method, you can quickly autogenerate a template:
Code:
#!/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

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


Technosaurus,
thank you, much appreciated Very Happy

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. Smile
and "hacked" this variant:
Quote:
#!/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

# time mki18n askpass alsawizard

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 Very Happy )
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2610
Location: www.eussenheim.de/

PostPosted: Thu 17 Nov 2011, 16:18    Post subject:
Subject description: pt_BR
 

ferro10n wrote:
Yeah, I forgot this isn't meant to work with other languages yet Laughing 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. Very Happy


Yes, this is Cutting Edge
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 Embarassed )

Thank you and good night (it is late here in Europe now)
Smile
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4424

PostPosted: Thu 17 Nov 2011, 19:50    Post subject:  

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:

Code:
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


replace trans.txt with your english file and tl=es with tl=??
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

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

Joined: 19 Jun 2010
Posts: 2610
Location: www.eussenheim.de/

PostPosted: Fri 18 Nov 2011, 06:51    Post subject:  

technosaurus wrote:
I am posting from my Droid so the following syntax will be "off"

[ -f /.../$LANG/app ] && LOCALES=/.../$LANG/app ¦¦ [ -f /.../${LANG%%_*} ] && LOCALES=/.../${LANG%%_*}
. $LOCALES

Seen this before your "edit"

That is: your one-liner can replace my two-lines code for enabling "regional variants" of language.
And LOCALES replaces LANGPATH.
_____________
edited later
and LOCALES is avoiding need of M/ under LOCALE Smile
_______________

Very nice. Thank you

Last edited by L18L on Fri 18 Nov 2011, 10:31; edited 2 times in total
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2610
Location: www.eussenheim.de/

PostPosted: Fri 18 Nov 2011, 07:20    Post subject:
Subject description: g
 

technosaurus wrote:
...

replace trans.txt with your english file and tl=es with tl=??
where ?? is
...

g** wrote:

Sorry, the page you requested contains a file type (application/octet-stream) we are unable to translate.
Crying or Very sad

my script wrote:
#!/bin/sh
echo -n > ./t12s_g_de
curl -A defaultbrowser \
-F "file=/dev/shm/t12s_askpass_en;type=text/plain" \
-F "sl=en" \
-F "tl=de" \
http://translate.googleusercontent.com/translate_f | while read A || [ "$A" ]; do
case $A in
"<meta"*)continue;;
*"<pre>"*)echo ${A##*"<pre>"} >> ./t12s_g_de;;
*"</pre>"*)echo ${A%%"</pre>"*} >> ./t12s_g_de;;
*)echo $A >> ./t12s_g_de;;
esac
done


g has been my friend until this happened
http://murga-linux.com/puppy/viewtopic.php?t=56869&start=33

Anyhow nice idea
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4424

PostPosted: Fri 18 Nov 2011, 07:29    Post subject:  

Ok, I've merged them together to get autotranslated locale files but all my trial and error caused me to exceed the max queries temporarily. Can someone try this on a _M_ formatted script:

Code:
#!/bin/bash
FROM=/C/
[ ! -d /usr/share/locales/C/ ] && mkdir /usr/share/locales/C/
for x in $@ ; do
   TEMPLATE=/usr/share/locales/C/${x##*/}
   while read -d$ A || [ "$A" ]; do
      case "$A" in
         *{_M_*)B=_M${A##*_M};B=${B%%\}*};echo ${B//:-/=};;
      esac
   done < $x >$TEMPLATE

for x in es yi cy sq ar hy az eu be bn bg ca zh-CN zh-TW hr cs da nl en et tl fi fr gl ka de el gu ht iw hi hu is id ga it ja kn ko la lv lt mk ms mt no fa pl pt ro ru sr sk sl es sw sv ta te th tr uk ur vi cy yi ; do
TO=/${x//-/_}/
[ ! -d ${TEMPLATE%%/C/*}/${x//-/_} ] && mkdir ${TEMPLATE%%/C/*}/${x//-/_}
curl -A firefox \
   -F "file=@$TEMPLATE;type=text/plain" \
   -F "sl=en" \
   -F "tl=$x" \
   http://translate.googleusercontent.com/translate_f | \
   while read A || [ "$A" ]; do
      case $A in
         "<meta"*)A="";;
         *"<pre>"*)A=${A##*"<pre>"};;
         *"</pre>"*)A=${A%%"</pre>"*};;
      esac
      [ "$A" ] && echo ${A// = /=\"}\"
   done > ${TEMPLATE//$FROM/$TO}
done
rm $TEMPLATE
done


Note: may need to have a .txt extension on the submitted file

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

Joined: 19 Jun 2010
Posts: 2610
Location: www.eussenheim.de/

PostPosted: Fri 18 Nov 2011, 09:39    Post subject: Starting translation supported by g  

Success Very Happy
technosaurus wrote:
...
Note: may need to have a .txt extension on the submitted file


# TEMPLATE=/usr/share/locales/C/${x##*/}
TEMPLATE=/usr/share/locales/C/${x##*/}.txt

I have run it for 6 languages
time
real 0m8.659s
user 0m0.292s
sys 0m0.076s


Spanish:
_M_1="Esta aplicación necesita para funcionar:"
_M_2="La contraseña del administrador se requiere:"
_M_3="Por favor introduzca la contraseña de administrador para ejecutar esta aplicación:"
_M_4 Tipo="admin contraseña necesaria para ejecutar esta aplicación:"
_M_5 =... No"
ferro10n, este esta bueno?
As a start for a good translation, better than English!

Wondering where the Tipo is coming from Rolling Eyes
Smile Very Happy
Back to top
View user's profile Send private message 
ferro10n

Joined: 15 Jun 2011
Posts: 106

PostPosted: Fri 18 Nov 2011, 16:59    Post subject: Re: Starting translation supported by g  

L18L wrote:
Success Very Happy
technosaurus wrote:
...
Note: may need to have a .txt extension on the submitted file


# TEMPLATE=/usr/share/locales/C/${x##*/}
TEMPLATE=/usr/share/locales/C/${x##*/}.txt

I have run it for 6 languages
time
real 0m8.659s
user 0m0.292s
sys 0m0.076s


Spanish:
_M_1="Esta aplicación necesita para funcionar:"
_M_2="La contraseña del administrador se requiere:"
_M_3="Por favor introduzca la contraseña de administrador para ejecutar esta aplicación:"
_M_4 Tipo="admin contraseña necesaria para ejecutar esta aplicación:"
_M_5 =... No"
ferro10n, este esta bueno?
As a start for a good translation, better than English!

Wondering where the Tipo is coming from Rolling Eyes
Smile Very Happy


This is from Google Translate, isn't it? Laughing Well, here's what the lines are supposed to be in Spanish:

Code:

_M_1="Esta aplicación quiere ejecutar:"
_M_2="Requiere contraseña de administrador:"
_M_3="Por favor introduzca la contraseña de administrador requerida para ejecutar esta aplicación:"
_M_4="Escribir contraseña de administrador requerida para ejecutar esta aplicación:"
_M_5="... Falló"


The 'Tipo' comes from 'Type', I think, which in that line should be 'escribir'. We don't have a special word for 'to write by keyboard' in Spanish, although there are heretic people who translate it as 'tipear'. Rolling Eyes

_________________
A beginner Puppy Linux user
Intel(R) Celeron(R) CPU 2.13GHz 512MB
LiveCD user
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4424

PostPosted: Fri 18 Nov 2011, 21:26    Post subject:  

Noone expects Google to get all the translating 100%, but at least its better than 0%.
Note that I use the Google translate site directly masked as FireFox with curl (wget cannot do right metadata for files), since the translate api is deprecated... So as long as the site itself is fairly stable, it should continue to work.

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

Joined: 15 Jun 2011
Posts: 106

PostPosted: Fri 18 Nov 2011, 21:35    Post subject:  

technosaurus wrote:
Noone expects Google to get all the translating 100%, but at least its better than 0%.
Note that I use the Google translate site directly masked as FireFox with curl (wget cannot do right metadata for files), since the translate api is deprecated... So as long as the site itself is fairly stable, it should continue to work.


Sorry, I didn't read the full posts Wink You're right, the translations may not be the most accurate, but they're understandable. As you said, it's better than 0%. You should make a PET Very Happy

_________________
A beginner Puppy Linux user
Intel(R) Celeron(R) CPU 2.13GHz 512MB
LiveCD user
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4424

PostPosted: Fri 18 Nov 2011, 22:39    Post subject:  

Now if I can just figure out how to connect piece G to happy.

I havent ironed out or commented on possible oopses or known issues ... For instance it won't work on translation variables that contain variables due to using $ as a separator... ${_M_1:-$hello world} would break the translation
... Still needs a bit of testing and documentation before people go installing it Willy nilly from a pet without looking at the code.

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

Joined: 19 Jun 2010
Posts: 2610
Location: www.eussenheim.de/

PostPosted: Sat 19 Nov 2011, 06:55    Post subject: oopses  

@ferro10n,
please forget what I have announced about another version (enabling pt_BR) for now. There is enough other stuff to be done before next version.

http://www.phrases.org.uk/meanings/willy-nilly.html Smile ________________

technosaurus wrote:
Now if I can just figure out how to connect piece G to happy.

I havent ironed out or commented on possible oopses or known issues ... For instance it won't work on translation variables that contain variables due to using $ as a separator... ${_M_1:-$hello world} would break the translation
... Still needs a bit of testing and documentation before people go installing it Willy nilly from a pet without looking at the code.


Known issue:
- wrong placement in variable name
_M_4 Tipo="admin contraseña necesaria para ejecutar esta aplicación:"

- other languages:
--Greek
_M_5 =... ÁðÝôõ÷å
(<- cannot make a red blank)
Should be
_M_5 =... απέτυχε
It is not just greek, also for example
-- Arabic
áÔä _M_5 =..."

- variable in message
I have tried finding a way to exclude something from translation.
(A decade ago I have prevented automated translation in a webpage using <q>term without translation</q>)

Now an example using 2 variables:
http://translate.google.com/#auto|es|Hello%20\%24{myOS}\%20world!%20\%24{myVersion}\%20rocks
Note, however that you cannot trust uppercase/lowercase

We always have the fallback solution to NOT let translate messages containing variables.

- quotes and double quotes have to be replaced in original script
This makes me think about making life easier for developer in first step of internationalization:
Mark messages by just _M_
Programm should add the unique ID numbers too
technosaurus wrote:
... it may be beneficial to change >$x.i18n to |sort -u >$x.i18n if you are planning to use a VAR multiple times

in addition to the replacement of quotes...
Back to top
View user's profile Send private message 
ferro10n

Joined: 15 Jun 2011
Posts: 106

PostPosted: Mon 28 Nov 2011, 00:35    Post subject:  

Posted about my last test in the Puppy Linux Help site.
_________________
A beginner Puppy Linux user
Intel(R) Celeron(R) CPU 2.13GHz 512MB
LiveCD user
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 2 of 5 [63 Posts]   Goto page: Previous 1, 2, 3, 4, 5 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.1236s ][ Queries: 12 (0.0115s) ][ GZIP on ]