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 22 May 2015, 15:25
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 5 of 5 [74 Posts]   Goto page: Previous 1, 2, 3, 4, 5
Author Message
L18L

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

PostPosted: Tue 07 Feb 2012, 17:12    Post subject: Re: xdelta_gui
Subject description: really strange
 

rodin.s wrote:
Same with version 0.5. Here is my translation. You can try it by yourself. It has something to do with UTF-8. Console messages were interesting.


I have used your file to /usr/share/locales/ru/xdelta_gui
-t12s from woof : did not translate, used UNDO button
-t12s v 0.5 : everything OK
-t12s from woof again: everything OK

Really strange

What are your console messages?
Back to top
View user's profile Send private message 
rodin.s

Joined: 22 Sep 2010
Posts: 339
Location: Ukraine

PostPosted: Tue 07 Feb 2012, 17:31    Post subject: t12s console messages  

Here is console messages file.
t12s_conslole.txt.gz
Description 
gz

 Download 
Filename  t12s_conslole.txt.gz 
Filesize  713 Bytes 
Downloaded  217 Time(s) 
Back to top
View user's profile Send private message 
L18L

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

PostPosted: Tue 07 Feb 2012, 18:07    Post subject: Re: t12s console messages  

rodin.s wrote:
Here is console messages file.

I see: just WARNINGs

# echo $LANG
de_DE.UTF-8
#
I have no such warnings and can read everything fine.
t12s_ru.png
 Description   
 Filesize   6.13 KB
 Viewed   503 Time(s)

t12s_ru.png

Back to top
View user's profile Send private message 
cusco-travel-services

Joined: 02 Mar 2015
Posts: 8

PostPosted: Mon 02 Mar 2015, 19:13    Post subject:  Usage of [ -f $LOCALES ] && . $LOCALES  

Hi L18L et al,

I've been using Linux for less than a year and 2 days ago I discovered this topic.

I like Technosaurus's idea for localisation of Bash scripts. It somewhat matches my thoughts of localisation for applications in that I think an indexed database containing all translations and using an Integer based index would be a more efficient mechanism instead of passing long strings of text as an index. There may be some valid reasons I don't know about but as someone who has programmed with databases for many years, I think that an indexed database should be much more efficient.

It appears that the following line of code is required each time a translation is to be accessed. Is that correct? If so, please explain for people new to Linux why it is needed each time.

Code:
[ -f $LOCALES ] && . $LOCALES

Also, in version 0.5 of your script the following block is different to what I have seen used and quoted elsewhere.

Code:
###################### copy this block into any other script that... ##########
app=\`basename \$0\`
T=/usr/share/locales # TEXTDOMAINDIR
# a one-liner to find existing translation file LOCALES allowing 'dialects'
[ ! -f \${T}/\${LANG%.*}/\${app} ] && LOCALES=\${T}/\${LANG%_*}/\${app} || LOCALES=\${T}/\${LANG%.*}/\${app}
[ -f \$LOCALES ] && . \$LOCALES # (re)load translation file (when using variables)
###################### ... uses this _ M _ method of internationalization #####

Notice, for example, that && is replaced by &&.

Thanks, Michael.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4507

PostPosted: Mon 02 Mar 2015, 22:15    Post subject: Re: Usage of [ -f $LOCALES ] && . $LOCALES  

cusco-travel-services wrote:
Notice, for example, that && is replaced by &&.

Thanks, Michael.
That looks like the result of pasting to a webpage (where "&" is represented by "&")
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
cusco-travel-services

Joined: 02 Mar 2015
Posts: 8

PostPosted: Mon 02 Mar 2015, 22:47    Post subject: Re: Usage of [ -f $LOCALES ] && . $LOCALES  

technosaurus wrote:
That looks like the result of pasting to a webpage (where "&" is represented by "&")


That's what I was thinking also.

What about all the \ characters?
Back to top
View user's profile Send private message 
cusco-travel-services

Joined: 02 Mar 2015
Posts: 8

PostPosted: Mon 02 Mar 2015, 22:53    Post subject:    

Additionally, if [ -f $LOCALES ] && . $LOCALES is required each time, which of the following will work?

Code:
[ -f $LOCALES ] && . $LOCALES # load translation file
[[ $DISPLAY ]] || { echo "${_M_04:-There is no xserver running. Exiting...}" ; exit 1 ; }

or
Code:
[ -f $LOCALES ] && . $LOCALES # load translation file
NoXserver="${_M_04:-There is no xserver running. Exiting...}"
[[ $DISPLAY ]] || { echo "$NoXserver" ; exit 1 ; }
Back to top
View user's profile Send private message 
L18L

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

PostPosted: Tue 03 Mar 2015, 06:21    Post subject: Re: Usage of [ -f $LOCALES ] && . $LOCALES  

Hello Michael
you wrote:
I like Technosaurus's idea for localisation of Bash scripts. It somewhat matches my thoughts of localisation for applications in that I think an indexed database containing all translations and using an Integer based index would be a more efficient mechanism instead of passing long strings of text as an index. There may be some valid reasons I don't know about but as someone who has programmed with databases for many years, I think that an indexed database should be much more efficient.

Thanks for making me search about official documentation about this method using index _M_nnn.

Actually not found any more.

Nobody has been using it.
And yes, there are reasons for not using it in Puppy.

So for me it is history now. Cool

I am thinking if you are developper, coder and maintainer all in one person you could give it a try.

Reloading the translation file is of course not always required,
-- only if the variable in the message has changed/another value than last loading.
-- and never required if command eval is used.

You could try everything if you had a Puppy Linux installed...
I am assuming you have not because of your
Quote:
Notice, for example, that && is replaced by &&.

Cheers
L

EDIT:
...and please do NOT use that crazy automatic translations
Quote:
Das Ziel des Cusco Travel Services ist, Reisende zu versorgen, zu und vom Cusco Gebiet von Peru, der beste Dienst der möglich ist für Ihre Bedürfnisse in Unterkunft, Passagiertransport und Touren wie zum die Inca-Spur, Beispiel Mountain-bike und Pferderücken Fahrend Ausflüge und Vorbehalte für Zugfahrkarten für die Züge der Inca Rail Bedienung zwischen Ollantaytambo und Machu Picchu und den Zügen der Peru Rail Bedienung zwischen Cusco (Poroy), Ollantaytambo und Machu Picchu und zwischen Cusco und Puno (See Titicaca).
Shocked Mad
Back to top
View user's profile Send private message 
cusco-travel-services

Joined: 02 Mar 2015
Posts: 8

PostPosted: Tue 03 Mar 2015, 15:52    Post subject:  Re: Usage of [ -f $LOCALES ] && . $LOCALES  

Hi L,

Thanks for your reply. I will continue modifying the script I want to interface with t12s and I'll let you know how it goes.

L18L wrote:
...and please do NOT use that crazy automatic translations
Quote:
Das Ziel des Cusco Travel Services ist, Reisende zu versorgen, zu und vom Cusco Gebiet von Peru, der beste Dienst der möglich ist für Ihre Bedürfnisse in Unterkunft, Passagiertransport und Touren wie zum die Inca-Spur, Beispiel Mountain-bike und Pferderücken Fahrend Ausflüge und Vorbehalte für Zugfahrkarten für die Züge der Inca Rail Bedienung zwischen Ollantaytambo und Machu Picchu und den Zügen der Peru Rail Bedienung zwischen Cusco (Poroy), Ollantaytambo und Machu Picchu und zwischen Cusco und Puno (See Titicaca).
Shocked Mad


Google Translate and Im Translator are what I used to create the German Translations for my website. Is "Google Translate" what you are referring to regarding "automatic translations"?

How bad is the German?

I wonder if Google Translate is better now? Laughing

Thanks for visiting my website.

Hasta luego, Michael.
Back to top
View user's profile Send private message 
cusco-travel-services

Joined: 02 Mar 2015
Posts: 8

PostPosted: Thu 05 Mar 2015, 00:13    Post subject:  Re: Usage of [ -f $LOCALES ] && . $LOCALES  

L18L wrote:
Reloading the translation file is of course not always required,
-- only if the variable in the message has changed/another value than last loading.
-- and never required if command eval is used.


HI L18L,

Are you saying that eval can be placed in a translated message that contains a variable reference (e.g. $variable) to resolve the value of the variable?

Can you give an example of using eval in the context to which you are referring?

Thanks, Michael.
Back to top
View user's profile Send private message 
L18L

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

PostPosted: Fri 06 Mar 2015, 08:34    Post subject: Re: Usage of [ -f $LOCALES ] && . $LOCALES
Subject description: eval
 

cusco-travel-services wrote:
Are you saying that eval can be placed in a translated message that contains a variable reference (e.g. $variable) to resolve the value of the variable?

Can you give an example of using eval in the context to which you are referring?


eval is outside.
In the context of gettext:
Code:
# #example
#echo "$(gettext 'hello $adjective world')"
hello $adjective world
#
#
# adjective='wonderful'
# echo "$(gettext 'hello $adjective world')"
hello $adjective world
#
# echo "$(eval echo `gettext 'hello $adjective world'`)"
hello wonderful world
#


And in our "new" syntax:
Code:
# echo "$eval ${_M_1:-hello $adjective world}"
 hello wonderful world
#


Try it yourself please.
regards

EDIT
Converting from and to .po format can be done (and has be done) simply of course.
Back to top
View user's profile Send private message 
cusco-travel-services

Joined: 02 Mar 2015
Posts: 8

PostPosted: Sat 07 Mar 2015, 16:31    Post subject:  Re: Usage of [ -f $LOCALES ] && . $LOCALES
Subject description: eval
 

L18L wrote:
eval is outside.
In the context of gettext:
Code:
# #example
#echo "$(gettext 'hello $adjective world')"
hello $adjective world
#
#
# adjective='wonderful'
# echo "$(gettext 'hello $adjective world')"
hello $adjective world
#
# echo "$(eval echo `gettext 'hello $adjective world'`)"
hello wonderful world
#


And in our "new" syntax:
Code:
# echo "$eval ${_M_1:-hello $adjective world}"
 hello wonderful world
#


Try it yourself please.
regards

EDIT
Converting from and to .po format can be done (and has be done) simply of course.


Hi L18L,

With a bit of online research and some trial and error, I actually managed to get eval working before I received your last reply although I don't understand all the mechanisms behind it. Smile

Hence, I have discovered and implemented the following techniques.

In order for a variable to NOT be resolved, when used in a String assigned to another variable, it needs to be escaped with a Backslash (i.e. \) before the $ symbol.

For example, if we have a variable named var1 which has a value of 123 (var1=123), then, the following statement ...

Code:
_M_01="This string references the variable var1 by using \$var1"

... will cause _M_01 to have a value of This string references the variable var1 by using $var1

Otherwise, if the following statement was used ...

Code:
_M_01="This string references the variable var1 by using $var1"

... the resulting value of _M_01 would be This string references the variable var1 by using 123

A variable reference, within a String, needs to be escaped with a Backslash when you want to use the eval Command to evaluate the string stored by the Referencing variable (i.e. _M_01) to retrieve the current value for variables referenced by _M_01.

This is important to consider, when included Code Source files reference variables of the including Script file, as referenced variables will be resolved immediately, when a Code Source file is included, unless they are escaped with a Backslash.

In relation to the techniques proposed by technosaurus, using these methods allows the retrieval of the current value of a Referenced variable (e.g. var1) without the need to reload a Code Source file.

For eval and/or echo to correctly parse New Lines, variables declared in the executed Script file or a Code Source file need to use '\n' for a New Line (Line Break). Actual line breaks can't be used.

The following code is an example of what I have implemented.

Code Source file
Code:
_M_01="Other language before new lines'\n\n'Other language after new lines \$var2"

Script file
Code:
var1="Text before new lines'\n\n'Text after new lines \$var2"
var1Yad=`eval "echo "${_M_01:-$var1}""`
yad --title "Title" --width 580 --center --text "$var1Yad"

However, with t12s, when entering '\n' or '\n\n' for a message the Single Quotes ' were being changed to Apostrophes ´ and I couldn't determine a way to escape the Single Quotes to stop them from being changed to Apostrophes which made testing difficult.

So, I commented the following line to prevent it from being executed.

Code:
#new_msgtr=`echo $new_msgtr | sed -e "s${delim}'${delim}´${delim}g"` # change quote to apostrophe

When restarting t12s, though, the Backslashes had been removed so that '\n\n' had become 'nn'.

Which line of code is causing that to happen? Could it be the following?

Code:
sed -r "s${delim}=\"${delim}\n${delim}g;s${delim}\"\$${delim}${delim}g" ${T}/${this_LANG}/${app} > /dev/shm/t # just for inspection

I also learnt that Round Brackets, ( and ), need to be escaped with a Backslash.

A bug I noticed with t12s is that when you click on the Ok button, to re-edit a message, the message is deleted and then you have to click on the Ok button again to re-enter text. Shocked

Thanks, Michael.
Back to top
View user's profile Send private message 
L18L

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

PostPosted: Thu 12 Mar 2015, 13:05    Post subject:  

Hi Michael,

you really want to dig into that stuff!

I have reread this thread from start and played with code again.

Without yad, I do not like yad any more.
I have used text editor geany (you can use very long lines and have them wrapped in the text editor)
New line is not really needed: we translate words, phrases, paragraphs,...
New line can b e set outside of translation I am sure.

I hav e tried this little example in our momanager, see http://murga-linux.com/puppy/viewtopic.php?t=81259&start=245 please.

Code:
# sample_i18n_t12s.pot
# created by /usr/sbin/t12s_xgettext
# on Thu Mar 12 17:43:28 CET 2015
# from /root/my-applications/bin/sample_i18n_t12s.sh
msgid ""
msgstr ""
"Project-Id-Version: sample_i18n_t12s\n"
"Language: de_BE\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Last-Translator: fido@localhost\n"
"Language-Team: none\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

# _M_1
msgid "hello world"
msgstr "Hallo Welt"

# _M_2
msgid "crazy"
msgstr ""

# _M_3
msgid "hello $x world"
msgstr ""

# _M_11
msgid "Now an example with some text before a new line."
msgstr ""

# _M_12
msgid "Now the example with some text after the new line."
msgstr ""


and this the the script
Code:
#!/bin/sh
export TEXTDOMAIN=sample_i18n_t12s
LOCALES=/usr/share/locales/${LANG%_*}/$TEXTDOMAIN
[ -f $LOCALES ] && . $LOCALES

x="${_M_2:-crazy}"

echo ${_M_1:-hello world}

[ -f $LOCALES ] && . $LOCALES
echo ${_M_3:-hello $x world}

echo ${_M_11:-Now an example with some text before a new line.}
echo ${_M_12:-Now the example with some text after the new line.}
 
echo "
that's it."
running (translation used)

Code:
# ./s*t12*
Hallo Welt
Hallo verrückt Welt
Jetzt ein Beispiel mit Text vor einer neuen Zeile.
Jetzt das Beispiel mit Text nach der neuen Zeile.

that's it.
#


My resume: use of eval was wrong. keep \n off .
Translators know po files. Use them.

Unforeseen nasty things may happen here.
Gettext is on the safe side:
If you change your code the not updated translation is not wrong, just not translated.

Thank you for making me look into that old (pre-momanager) stuff.
L
Back to top
View user's profile Send private message 
cusco-travel-services

Joined: 02 Mar 2015
Posts: 8

PostPosted: Tue 17 Mar 2015, 23:32    Post subject:    

Hi L,

Sorry for the late response.

Why do you not like yad any more?

What are you using instead of yad?

I think yad and zenity could use more formatting options. For example, fixed width columns that vertically expand for Form fields.

I visited the other topic and downloaded the momanager-20150309.pet file but I wasn't able to extract anything from it. How do I do that?

Are you using momanager to create the .pot files?

Is the Script, you posted, using gettext to read from a .mo file?

In the Script you have the following for example.

Code:
${_M_1:-hello world}


Where is the _M_1 variable declared?

I don't understand, exactly, what you are trying to say with the following.

L18L wrote:
My resume: use of eval was wrong. keep \n off.


I think the following is probably only a management issue. If you change text that needs an updated translation, then, a new template should be issued to the translators so that updated translations can be provided.

L18L wrote:
If you change your code the not updated translation is not wrong, just not translated.


For example, a template could be like the following.

Code:
#_M_01="Text to be translated"
_M_01=""

#_M_02="More text to be translated"
_M_02=""


In its present incarnation t12s can be used to help create a Source template file which you can edit directly for the translations instead of trying to enter the translations via the t12s interface.

With some extra "spit and polish" I think it would be a very worthwhile utility. Smile

Thanks and hasta pronto, Michael.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 5 of 5 [74 Posts]   Goto page: Previous 1, 2, 3, 4, 5
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.1371s ][ Queries: 13 (0.0162s) ][ GZIP on ]