Page 1 of 1

MoManager tips for gettext translations

Posted: Tue 05 Feb 2013, 00:03
by don570
MoManager tips for gettext translations of scripts

See pupmd5sum.sh as a model to follow.

A utility to make minor changes to entries
build_gettext is available.

Shinobar does a good job explaining how to localize HERE

Note to make a mo file for French your $LANG must be French
and devx file for your distribution must be loaded.
Run a recent version of MoManager (Dec 2012) since
there was bugs in early versions.

Here are my experiences with using MoManager on a script...

1)Barry K has instructions (in MoManager help)
about adding a couple of lines near beginning of script.
Near beginning of script put two lines

Code: Select all

export TEXTDOMAIN=script_name
export OUTPUT_CHARSET=UTF-8
(where you do a replacement for script_name)

if you want to use eval_gettext (rare) then you must also
put the following before eval_gettext is evoked

Code: Select all

. gettext.sh

Go thru script and replace English expressions with
$(gettext "TEXT_to_TRANSLATE")




2) If text has an apostophe see this page
http://murga-linux.com/puppy/viewtopic.php?t=84086

3) Check script file in Geany by using Find 'get' command
This will list all occurrences of 'gettext'. Check the spelling
carefully. I guarantee that there will be mistakes.

4) Run the script in a terminal (you can use ./script_name)
and read error messages. Script must be executable of course.
Line numbers reported by terminal won't be accurate
if you have a gtkdialog script.

5) When your script will run without complaint in the terminal, then
put it in a folder that holds executable apps (example /usr/bin/)

6) I suggest that you install poedit It can be found HERE

7) Launch MoManager from start menu or terminal (it is launched in terminal by typing
'poeditor'). At the top right of window there will be a list of scripts
that need a mo file. --> mo file is the final file of translations.
Tick 'edit with poedit' and click Create button. The procedure is
fairly straight forward but if you haven't prepared your script properly
you will have problems. If you do have problems it is
time to quit. Unfortunately MoManager creates files on your hard disk
that will cause subsequent problems even if you do correct your script.

...But here is the solution to these problems....

1)Trash the folder /tmp/momanager
2) Trash the mo file if it has been created in
/usr/share/locale/fr/LC_MESSAGES/ (assuming French is current
language) In fact you should remove the German,Spanish and other
translations of your script if they exist.
Note: You can check the time of creation if in doubt about who
created the mo file

3) Trash the pot file in /usr/share/doc/nls/script_name

You now have a fresh system that won't confuse MoManager.
Correct your script and run MoManager again.


Another tip ---> I've had problems when I add more gettext
entries to a script. This means that more translation entries are needed.

The method I used ---> make a pet package, holding just the script.
Be careful the correct files are inside!! No mo or pot files inside.
Save old mo files somewhere safe.

Now go through the 3 step procedure I wrote above to obtain a fresh installation.
Now install your script which is easy since
you made a pet package. Now run Momanager and it will
think the script has no tranlation yet and create a mo file from scratch.
It's fairly easy to fill in the entries again.

Alternatively you can put back a mo file (if it is correctly formed!!)
just before launching MoManager and poedit will look
like this (see image) The untranslated expressions will
be on top of list. A nice feature of poedit. Everything
should be straight forward. mo and pot files can be created and saved.

Image

____________________________________________________

Posted: Tue 05 Feb 2013, 03:22
by vicmz
Thank you don570, very useful.

I recommend to link to this POedit package, often links from the openlab repo break.

Re: MoManager tips for gettext translations

Posted: Thu 07 Feb 2013, 19:23
by L18L
don570 wrote:...
Here are my experiences with using MoManager on a script...
...
The experiences described here are
not with "just translate"
but with changing the code in a script to enable translations

momanager was built to enable translations of puppy in one GUI.

-------

For people who want to try making a script "international" I suggest another approach (how I do it):

1- put in the 2 lines (TEXTDOMAIN and OUTPUT_CHARSET) into the script
2- start with "gettexting" 1 message (title or frame)
3- start your script to make sure it can run
4- start momanager and select the new item and translate that 1 message
5- (re)start your script, you should see that translated message
6- if not search the fault and/or ask!
7- have a break or stop for this day or finish
8- goto 2

Posted: Thu 07 Feb 2013, 19:56
by don570
L18L wrote:2- start with "gettexting" 1 message (title or frame)
When I gettexted 'pupmd5sum.sh I used a different method as you noted.

I worked entirely in English. By a miracle :lol: I was able to convert
to gettext and track down the errors fairly quickly but working with
MoManager is tough. I had a bad experience because I had typed in the
wrong script name(Shinobar had given pupmd5sum.sh a different name)
export TEXTDOMAIN=script_name

It took me some time to track down that error and then it took me
more time to realize that I needed to clean my installation of old
files created by MoManager . In other words I needed a 'fresh' installation.

What irks me about MoManager is that it takes 2 minutes at least for
it to launch on my machine, so if I have to do that each time
I do a conversion of a expression into English gettext I'll go nuts. :cry:

So I think the best method is to do just one translation of an expression
into French and check that everything is okay.

Then proceed to do a conversion of all the English gettext script expressions using Geany.

Then switch to French with country wizard and launch MoManager
to translate script to French. Hopefully MoManager will see the
previous mo file that was created and react appropriately i.e. create
a po file that poedit can open.

____________________________________________________________

Posted: Thu 07 Feb 2013, 20:24
by L18L
don570 wrote:export TEXTDOMAIN=script_name
Yes, that is exactly why I suggest to start with just 1 message!

Of course you advance to make more than 1 per run

2 minutes for momanager is slow
my (1.5GHz) box needs exactly 1 minute (very long for small changes)

The great advantage with momanager is the easy update after changes in the script.

Note, use command line

Code: Select all

msgfmt script.po -o - > /usr/share/locale/fr/LC_MESSAGES/script.mo
to test new translation and you are faster.

If your LANG is en_CA then you can start your script in french

Code: Select all

LANGUAGE=fr script

Posted: Thu 07 Feb 2013, 20:37
by don570
My computer is so slow because it is an old installation of Exprimo that
has a lot of scripts loaded. I will set up a new install that has
the minimum number of scripts for max speed.

______________________________

Posted: Mon 11 Feb 2013, 22:36
by don570
I have found the following useful to test a script to see if its gettext
expression is suitable...


Method:

1) change name of old script from script_name to script_name1

2) change the line near beginning of script from
export TEXTDOMAIN=script_name
to
export TEXTDOMAIN=script_name1

3) the script must be executable for MoManager to detect it....
chmod 755 script_name1

Now make sure you're in a foreign language such as de
and launch MoManager , and find script_name1 in upper rightside
of window (It will be listed with the untranslated scripts)

After translating the expression with Poedit
--> check German translation by launching script in terminal

Code: Select all

Language=de script_name1
If everything has gone well then the German translation will show
correctly

Image


.

quick update mo-file

Posted: Sat 16 Feb 2013, 19:59
by rodin.s
Sometimes when translating a script I need to see if it looks good on GUI and I make some small changes to translation. But MoManager updates long time so my solution is go to /tmp/momanager:

Code: Select all

cd /tmp/momanager
and do this

Code: Select all

cp jwmconfig2.mo /usr/share/locale/ru/LC_MESSAGES/
every time when I do small changes to translation. Then I run the translated application to see how it looks.
As I use Poedit mo-file is created when I press Save button. When translation is complete I use MoManager.

Posted: Sat 16 Feb 2013, 20:23
by don570
Can it be done as one command line in the terminal?

Code: Select all

cp /tmp/momanager/jwmconfig2.mo /usr/share/locale/ru/LC_MESSAGES/
_______________________________________

L18L warned me about pre-existing pot files. I read Barry's
instructions and saw the following...

MoManager will automatically use any pre-existing .pot file that it
finds in /usr/share/doc/nls, rather than use xgettext to extract the strings
from the script(s).
I now realize why I was having problems with moManager


I did a check of this and I found that if make modifications
to the text strings that deleting the pot file in /usr/share/doc/nls was
absolutely necessary!!!

.

one line

Posted: Sat 16 Feb 2013, 20:58
by rodin.s
Of course it could be done in one line but I usually go to /tmp/momanager and I use "ls" command to see the content of that directory to choose needed mo-file. Or I could use:

Code: Select all

ls /tmp/momanager 
and then use above one line.

error in translation - characters wrong type

Posted: Tue 19 Feb 2013, 18:16
by don570
While I was putting together my textstrings script (for the
localisation of my rightclick pet package)I found the following
command line to create a pot file valuable...

Code: Select all

xgettext -L shell textstrings -o textstrings.pot

It produced an error message in the terminal --->
saying that I hadn't used ASCII characters at line 50

For some strange reason an entry "Add file to pmusic list"
had bad characters??? I rewrote the line in utf-8 characters
and the line of code worked fine.

So this command is a good way to check for bad characters.
The application POEDIT doesn't give a proper warning!!


.

xgettext

Posted: Tue 19 Feb 2013, 18:30
by rodin.s
I always use this command while adding gettext to scripts to check if everything is correct. I usually use output to terminal like this:

Code: Select all

xgettext -L shell some_script.sh -o - 

Posted: Wed 20 Feb 2013, 20:38
by don570
This is the file that has the bad characters at line 50

People can use it to test the command xgettext.

Remove the extension to obtain script...

.

Posted: Thu 21 Feb 2013, 12:58
by L18L
Your white space between Pmusic and Playlist is not ASCII.
It is not really bad, just UTF-8 8)

Code: Select all

# xgettext -L shell textstrings
xgettext: Non-ASCII string at textstrings:50.
          Please specify the source encoding through --from-code.
# 
# xgettext --from-code=UTF-8 -L shell textstrings
#

Re: quick update mo-file

Posted: Sun 05 May 2013, 18:03
by L18L
rodin.s wrote:Sometimes when translating a script I need to see if it looks good on GUI and I make some small changes to translation. But MoManager updates long time...
Long time for update is history now. :)

Try latest momanager please.
Get it from 5th post of http://www.murga-linux.com/puppy/viewtopic.php?p=701995

Posted: Mon 06 May 2013, 17:06
by don570
Your white space between Pmusic and Playlist is not ASCII.

I did a lot of copying of text using the clipboard, since this reduced the
number of spelling mistakes and speeded up the process of writing the script.

Maybe Zigbert put in whitespace with hard spaces(the alt key).
This is something I would never do.

When I typed out the 'Add to pmusic playlist' menu item it solved the
problem.

Fortunately the US-keyboard layout does a good job at showing
the characters that programmers use.


______________________________________________________

Posted: Tue 06 Aug 2013, 16:35
by don570
I did French and German translation of puppy-rsync

I found that using poedit would result in an error message,
but momanager would still create the various translation files (pot,po,mo)

However whenever I tried to launch poedit again I would get errors
reported. I discovered an interesting line in the po file indicating that
ASCII was the text format used which was obviously wrong.

My method to fix was following

1) use momanager and launch translation with geany rather than poedit
2)geany opens the script for tranlation. Using clipboard
I transfer previous translations made in poedit to geany.
I make a change of the following line to UTF-8

Code: Select all

"Content-Type: text/plain; charset=UTF-8\n"
3) Save and quit geany. There is message that says that mo file
is created. When I check this mo file has few or no flaws in it :lol:
so it is useful.


Here is the beginning of po file for reference....

Code: Select all

msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-08-06 06:59-0400\n"
"PO-Revision-Date: 2013-08-06 06:19-0400\n"
"Last-Translator: root <don570@hotmail.com>\n"
"Language-Team: German <translation-team-de@lists.sourceforge.net>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
_______________________________________________

Posted: Thu 29 Aug 2013, 20:12
by don570
I was converting several scripts from the old fashioned Zigbert's method
of localization to gettext locallization and I found that the only way I
could make the scripts work properly was to put 'set -a' near beginning of
script. This allows the variable values to be sent to functions??

I found in the script baconrecorder that set -a had to be written before
the gettext.sh script is loaded like this...

Code: Select all

set -a
. gettext.sh
I don't know why but that is the order required.

__________________________


Another tip ---> Be sure that all non- ascii characters are removed from script.

You can test the script you've written with this command . Of course
devx file must be loaded to execute this command.

Code: Select all

xgettext -L shell some_script.sh -o -
__________________________________________

Another tip---> When using eval_gettext --->
Don't forget to put three slashes in front of dollar sign which represents
the contents of a variable.

Code: Select all

`eval_gettext \"Bacon Recorder \\\$VERSION\"; echo`
__________________________________________

Another tip: Don't confuse the dollar sign when it's being used
as the contents of a variable with the results of a command.

In that case the three slashes doesn't work (apparently)

For an example ---> the result of a date command ---> $( date )
must be loaded into another variable ----> TIME_START

Code: Select all

TIME_START="$( date )"
...
...
echo "`eval_gettext \"The recording started at \\\$TIME_START\"; echo`"    >>  $WORKDIR/log
Then that new variable can be treated as standard variable containing
data i.e. a string, so I now put three slashes in front of dollar sign.




_________________________________________________

Posted: Sat 31 Aug 2013, 18:19
by don570
Another tip :

If you accidentally make a mo file for de_CH rather than de locale,
it's easy to make the change. Just drag mo file over to the
equivalent mo folder i.e. /usr/share/locale/de/LC_MESSAGES/
Then launch momanager and choose the script again --->

It will read 'de' beside the script name rather than de_CH

Do a 'Save' then 'Quit' in poeditor and the corrected mo file will be created
(including in /root/ and /tmp/)

_________________________________________