Page 2 of 4

Re: zigbert and gettext -automate

Posted: Wed 01 Aug 2012, 19:27
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 :?:

locale2gettext v0.1

Posted: Thu 02 Aug 2012, 03:22
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]

Re: locale2gettext v0.1

Posted: Thu 02 Aug 2012, 12:52
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.

replace variables by gettext expression

Posted: Thu 02 Aug 2012, 13:04
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.

Re: replace variables by gettext expression

Posted: Thu 02 Aug 2012, 13:13
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.

Re: replace variables by gettext expression

Posted: Thu 02 Aug 2012, 13:33
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.

Re: replace variables by gettext expression

Posted: Thu 02 Aug 2012, 23:26
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.

Posted: Fri 03 Aug 2012, 06:54
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

Posted: Fri 03 Aug 2012, 19:57
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 "Им

Gettext in pBurn.

Posted: Fri 03 Aug 2012, 21:35
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...

pfind

Posted: Sat 04 Aug 2012, 18:24
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.......

Re: Gettext in pBurn.

Posted: Sat 04 Aug 2012, 18:35
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

zigbert2gettext-0.1

Posted: Sun 05 Aug 2012, 11:05
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.

Posted: Sun 05 Aug 2012, 11:18
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

pBurn updated

Posted: Sun 05 Aug 2012, 13:42
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.

ptiming

Posted: Sun 05 Aug 2012, 18:11
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 
#

Posted: Fri 10 Aug 2012, 06:28
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

pburn

Posted: Fri 10 Aug 2012, 10:54
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

Re: pfind

Posted: Fri 10 Aug 2012, 11:09
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

Re: pfind

Posted: Fri 10 Aug 2012, 11:48
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.