zigbert and gettext

For efforts in internationalising Puppy and solving problems in this area
Message
Author
User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: zigbert and gettext -automate

#21 Post by L18L »

shinobar wrote:Mostly it works. But some case, we need to modify the original...
I have tested it with SOURCE=/usr/local/pfilesearch/locales
Does convert half (just the trailing ) ) for
export ....
and more than 1 liners

Examples:
export LOC_NO="No")
LOC_QUIT=$(gettext "Quit")

Missing
'$(gettext '
can easily be inserted manually.
------

Converting also the existing translations would be great :?:

User avatar
shinobar
Posts: 2672
Joined: Thu 28 May 2009, 09:26
Location: Japan
Contact:

locale2gettext v0.1

#22 Post by shinobar »

Full automation is difficult. But it will hopefully be an useful tool.
Unzip the attached, add executable, place at /root/applications/bin or somewhere under the $PATH.

# locale2gettext --help
locale2gettext 0.1
Convert locales of zigbert into gettext version.
usage: locale2gettext [PATH_TO_LOCALE_FILE] [TEXT_DOMAIN]
Attachments
locale2gettext.gz
Unzip, add executable, place at /root/applications/bin
(1.11 KiB) Downloaded 553 times
Downloads for Puppy Linux [url]http://shino.pos.to/linux/downloads.html[/url]

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: locale2gettext v0.1

#23 Post by L18L »

shinobar wrote:Full automation is difficult. But it will hopefully be an useful tool.
Yes it is helpful, has been running successfully for pfilesearch

I have tried to put the gettext into the script
(easier to understand and to maintain)
Does not work with multi line messages
But I got pfilesearch running with this:

Code: Select all

#!/bin/sh

# replace variables by gettext expression
# example:
# LOC_OPTIONS=$(gettext "Options") # line in locales.converted
# line in script:
#     <frame $LOC_OPTIONS>
# will become:
#     <frame $(gettext "Options")>
#

input_file=locales.converted
# create sed file
conversion_file=locales.sed
delimiter='@' # not used in script ???
echo "#sed expressions for conversion of pfilesearch" >  $conversion_file
while read LINE; do
 case "$LINE" in
 \#*) continue                                                           # skip comments
      ;;
   *) [ -z "$LINE" ] && continue                                         # skip blank lines
      [ "`echo $LINE | grep '^export TEXTDOMAIN='`" ]     && continue    # skip
      [ "`echo $LINE | grep '^export OUTPUT_CHARSET='`" ] && continue    # skip
      [ "${LINE:0:7}" = "export " ] && LINE="${LINE//export }"           # delete 'export '
      LINE="${LINE//=\$\(/$delimiter\$(}"                                # s#FROM${delimiter}TO#
      [ "${LINE:0:3}" = "LOC" ] && LINE="s${delimiter}${LINE//\$}"       # s${delimiter}FROM#TO#
      [ "`echo $LINE | grep -E '"\)$'`" ] && LINE="${LINE}${delimiter}" # s#FROM$#TO${delimiter}
      ;;
 esac
 echo $LINE >> $conversion_file
done < $input_file
echo finished $conversion_file

# delete multiliners
cat $conversion_file | grep -E "^s${delimiter}LOC" | grep -E "${delimiter}$"  > $conversion_file.1liners
echo finished $conversion_file.1liners

# replace $LOCxxx by gettext (....)
sed -f $conversion_file.1liners pfilesearch > pfilesearch.converted
echo finished pfilesearch.converted
chmod +x pfilesearch.converted

echo run converted script in console to see errors !
echo some errors can be fixed by escaping quotes !!
echo do not forget to the muliliners !!!
Feel free to add it (maybe change some variables) to your locale2gettext

I am going to convert pfind now. That is the most logical step after pfilesearch.

User avatar
shinobar
Posts: 2672
Joined: Thu 28 May 2009, 09:26
Location: Japan
Contact:

replace variables by gettext expression

#24 Post by shinobar »

L18L wrote:# replace variables by gettext expression
# example:
# LOC_OPTIONS=$(gettext "Options") # line in locales.converted
# line in script:
# <frame $LOC_OPTIONS>
# will become:
# <frame $(gettext "Options")>
Why we need it?
L18L wrote:(easier to understand and to maintain)
I am not sure.
Downloads for Puppy Linux [url]http://shino.pos.to/linux/downloads.html[/url]

User avatar
shinobar
Posts: 2672
Joined: Thu 28 May 2009, 09:26
Location: Japan
Contact:

Re: replace variables by gettext expression

#25 Post by shinobar »

If we convert only the file 'locales' and do not change any of others, it allows backward compatibility, i mean we can use old NLS as is.
Downloads for Puppy Linux [url]http://shino.pos.to/linux/downloads.html[/url]

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: replace variables by gettext expression

#26 Post by L18L »

shinobar wrote:If we convert only the file 'locales' and do not change any of others, it allows backward compatibility, i mean we can use old NLS as is.
yeah, that is true.

But new apps should be coded without the LOCxx variables
It is easier to use just gettext inside the script.

User avatar
shinobar
Posts: 2672
Joined: Thu 28 May 2009, 09:26
Location: Japan
Contact:

Re: replace variables by gettext expression

#27 Post by shinobar »

shinobar wrote:If we convert only the file 'locales' and do not change any of others, it allows backward compatibility, i mean we can use old NLS as is.
But it is not a good idea...
The script takes the older NLS if there are both old and new.
Downloads for Puppy Linux [url]http://shino.pos.to/linux/downloads.html[/url]

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#28 Post by zigbert »

L18L wrote:I am going to convert pfind now. That is the most logical step after pfilesearch.
Great!!!
shinobar wrote:If we convert only the file 'locales' and do not change any of others, it allows backward compatibility, i mean we can use old NLS as is.
Gettext has the advantage of making the code more readable (also for me :D ). That is a good thing for the community. Converting the locales-file would sure be good for backward compatibility, but for moving the project further, I think updating the code itself is the way to go.


Sigmund

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#29 Post by L18L »

zigbert wrote:updating the code itself is the way to go.
:)
There is always something to learn and something to improve.

Generating po files from the old locals is also possible.

Code: Select all

# LOC200
msgid "Filename"
msgstr "Им
Attachments
pfind_semi_ru.png
LANGUAGE=auto:ru:de
(35.79 KiB) Downloaded 678 times

rodin.s
Posts: 344
Joined: Wed 22 Sep 2010, 19:50
Location: Ukraine

Gettext in pBurn.

#30 Post by rodin.s »

I have added gettext to pBurn but haven't tested it well yet. Just tested main GUI and have made partial Russian translation for testing. I haven't change set-language section of pburn script so translation only works if I choose or type in 'ru' language in Preferences.
I also didn't know what to do with line 398 of func_gui_options.
New MoManager finds all files and creates proper pot-file.
I didn't internationalize file func_man since it didn't have '$LOC' before...
Attachments
pburn_gtxt-3.7.3.pet
Pburn with gettext. Not tested. Some mistakes possible.
(71.67 KiB) Downloaded 553 times
MoManager-ru_UA-pburn-3.7.3.tar.gz
partial Russian translation just for testing ... I will update it soon.
(3.69 KiB) Downloaded 549 times

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

pfind

#31 Post by L18L »

Please test version 5.02

NLS has German (of course) and Russian (converted from old system)

So you can change between de, ru and English

Next I will try to convert the other languages.......
Attachments
pfind_changeLANGUAGE.png
(7.97 KiB) Downloaded 814 times
pfind-NLS.pet
Russian (to be completed) and German
(8.45 KiB) Downloaded 656 times
pfind-5.02.pet
(18.72 KiB) Downloaded 696 times

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: Gettext in pBurn.

#32 Post by L18L »

rodin.s wrote:...I haven't change set-language section of pburn script so translation only works if I choose or type in 'ru' language in Preferences....
Hope you understand my solution in pfind ( used it in ymount some time ago :lol: ) Search for LANGUAGE NEW_LANGUAGE and LANGUAGES

Sorry I cannot help very much with testing because I do NOT have CD burner

User avatar
shinobar
Posts: 2672
Joined: Thu 28 May 2009, 09:26
Location: Japan
Contact:

zigbert2gettext-0.1

#33 Post by shinobar »

zigbert wrote:Gettext has the advantage of making the code more readable (also for me :D ). That is a good thing for the community. Converting the locales-file would sure be good for backward compatibility, but for moving the project further, I think updating the code itself is the way to go.
OK, the first trial to place gettext inline the code.
But for multiple lines, i think we are better to stay the substitution method, that is:

Code: Select all

export LOCXXX=$(gettext "First line
Second lne")
export DIALOG="<text><input>echo -n "\$LOCXXX"</inout></text>"
Extract the attached, add executable, place it at /root/my-applications/bin.
# zigbert2gettext --help
zigbert2gettext 0.1
Convert zigbert apps into gettext version.
usage: zigbert2gettext [PATH_TO_MAIN_SCRIPT] [TEXT_DOMAIN]
PATH_TO_MAIN_SCRIPT - example: /usr/local/pburn/pburn

But still you need to remove manually some code, loading the locales file, from the converted main script.
Attachments
zigbert2gettext.gz
Unzip, add executable, place at /root/my-applications/bin.
(2.3 KiB) Downloaded 691 times
Downloads for Puppy Linux [url]http://shino.pos.to/linux/downloads.html[/url]

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#34 Post by zigbert »

Hi guys
I am a bit out of time for Puppy right now.
I will try to catch up within a few days.


Thank you all for your effort to push Puppy forward.
Sigmund

rodin.s
Posts: 344
Joined: Wed 22 Sep 2010, 19:50
Location: Ukraine

pBurn updated

#35 Post by rodin.s »

I did some tests on pBurn. Tried to burn CD-R. Seems OK. I have also completed translation of mo-file: just have copied lines from old locale file in Poedit with some modifications.
I have also made some changes to previous pet: commented out set-locale this time.
I changed some translation lines for example:
Blank Disc - To blank the disc
and
Blank Disc - The disc is blank
have different translation so I have added whitespace to 'Blank Disc ' in func.
Same with 'Burn ISO-image' button in GUI: to burn and the burn have different translations.
Attachments
pburn_gtxt2-3.7.3.pet
Updated pBurn
(71.7 KiB) Downloaded 609 times
MoManager-ru_UA-pburn-3.7.3.tar.gz
Full Russian translation this time.
(14.14 KiB) Downloaded 599 times

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

ptiming

#36 Post by L18L »

L18L wrote:...Next I will try to convert the other languages.......
done
using shinobar's locale2gettext in

Code: Select all

#!/bin/sh
#
# convert translation file "Zigbert" to "Gettext"
# convert /usr/local/app/locals/LANG to /usr/share/locale/language/app.mo
#   which then can be checked/modified using momanager
# 20120805 by L18L

apps="`find /usr/local -name locals | cut -d'/' -f4`" # pburn pfind pfilesearch ... 
apps="ptiming" # no, just pvd for now

for app in $apps; do
 [ "$app" = "pfind" ] && continue
 [ "$app" = "pfilesearch" ] && continue
 SOURCE=/usr/local/$app/locales
 [ -f "$SOURCE" ]  ||  SOURCE=/usr/local/$app/locals/en_US:english
 [ -f "$SOURCE" ]  ||  continue                   # nothing to translate here
 echo " converting /usr/local/$app ..."

 # locale2gettext usage: $APPNAME [PATH_TO_LOCALE_FILE] [TEXT_DOMAIN]" 
 [ -f "$SOURCE.converted" ] || locale2gettext $SOURCE
 # $SOURCE.converted has LOCxxx=$(gettext "bla bla")
  
 langs=`ls /usr/local/$app/locals | cut -d'_' -f1 | sort -u`
 for lang in $langs; do # for each language
  [ "$lang" = "en" ] && continue
  echo "       from /usr/local/$app/locals/$lang ..."
  # input
  TEMPLfile=$SOURCE.converted
  # we know just ru and must say ru_RU
  LOCfile=`ls /usr/local/$app/locals/$lang* | head -n1`
  # output
  LOCfilePO=$LOCfile.po
 
echo '#, fuzzy
msgid ""
msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
' > $LOCfilePO

  while read LINE ; do
   case $LINE in
   \#*) continue                                                           # skip comments
        ;;
     *) [ -z "$LINE" ] && continue                                         # skip blank lines
        [ "`echo $LINE | grep '^export TEXTDOMAIN='`" ]     && continue    # skip
        [ "`echo $LINE | grep '^export OUTPUT_CHARSET='`" ] && continue    # skip
        [ "`echo $LINE | grep '^set'`" ]                   && continue     # skip
        [ "${LINE:0:7}" = "export " ] && LINE="${LINE//export }"           # delete 'export '
      
        LINEid=`echo $LINE | cut -d '=' -f1` 
        msgid=`echo $LINE  | cut -d '"' -f2` 
        msgstr=`grep $LINEid $LOCfile | cut -d '"' -f2 | head -n1` 
        
        [ "`grep $LINEid $LOCfilePO`" ] && continue                         # avoid douplicates
        #echo "# $LINEid"
        #echo "msgid "$msgid""
        echo "msgstr "$msgstr""
        #echo ""

        echo "# $LINEid" >> $LOCfilePO
        echo "msgid "$msgid"" >> $LOCfilePO
        echo "msgstr "$msgstr"" >> $LOCfilePO
        echo "" >> $LOCfilePO

        ;;
   esac
  done < $TEMPLfile
  
  # create mo file and delete po file
  if [ "`msgfmt -o /usr/share/locale/$lang/LC_MESSAGES/$app.mo $LOCfilePO`" ]; then
   echo could not create /usr/share/locale/$lang/LC_MESSAGES/$app.mo
  else 
   rm $LOCfilePO
   echo /usr/share/locale/$lang/LC_MESSAGES/$app.mo created
  fi
  echo ''
 done # lang
 echo " ... $app converted"
 rm $SOURCE.converted
done # app
echo "finished

You can edit the translations using momanager
"
exit 0
And in the created /usr/local/ptiming-converted just change this:

Code: Select all

##set language
#. $APPDIR/locals/en_US:english #always run to fill gaps in translation
#LANGUAGE="`ls -1 $APPDIR/locals/ | grep ${LANG%.*}`"
##fallback to macrolanguage if available (ISO 639-1 two letter code: en, es, fr, etc.)
#if [ -z $LANGUAGE ]; then LANGUAGE="`ls -1 $APPDIR/locals/ | grep ${LANG%_*}:`"; fi
#[ "$LANGUAGE" != "en_US:english" ] && . $APPDIR/locals/$LANGUAGE 2> /dev/null 
#
Attachments
ptiming_converted.png
(30.03 KiB) Downloaded 729 times

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#37 Post by zigbert »

Pburn is updated with gettext - thanks a lot.

I have some time today - let's see what I get done..... will be back after the weekend


Sigmund

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

pburn

#38 Post by L18L »

zigbert wrote:Pburn is updated with gettext
downloaded version 3.7.4 shows as 3.7.3

Anyhow, I have converted all languages to pburn.mo using rodin.s `s version above.

So everyone will have to start not from zero


---

edit
going to test version now
Attachments
pburn_NLS.pet
some locals converted to pburn.mo
(48.96 KiB) Downloaded 631 times

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

Re: pfind

#39 Post by zigbert »

L18L wrote:Please test version 5.02
$TEXTDOMAIN=pfilesearch in your pFind. I guess it's because there only can be one text domain, and code from pFilesearch is embedded into pFind.

That means NLS files for pFilesearch will contain gettext-strings for both pFind and pFilesearch? Not the best solution for those who uses only pFilesearch as a backend for pBurn/pMusic.... My intention is to separate the backend and frontend.

What is the downside of having an unique $TEXTDOMAIN=pfind?


Sigmund

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: pfind

#40 Post by L18L »

zigbert wrote:$TEXTDOMAIN=pfilesearch in your pFind. I guess it's because there only can be one text domain, and code from pFilesearch is embedded into pFind.
Good guess!
That was before Barry changed momanager.
Now everything is possible:
I will separate them and make a version 5.03
TEXTDOMAIN=pfind
and pfilesearch using TEXTDOMAIN=pfilesearch containing the messages from pfilesearch only.

Post Reply