Difference between revisions of "Translating gettext"

From Apertium
Jump to navigation Jump to search
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Traduction des fichiers gettext|En français]]

Apertium does not have a built-in [[Format handling|format handler]] for gettext / .po-files; however, there are excellent tools available which can use Apertium to translate these files. For command-line and batch usage, Pology is recommended; if you want Apertium to give suggestions in a po-editor, try Virtaal.
Apertium does not have a built-in [[Format handling|format handler]] for gettext / .po-files; however, there are excellent tools available which can use Apertium to translate these files. For command-line and batch usage, Pology is recommended; if you want Apertium to give suggestions in a po-editor, try Virtaal.


==Pology==
==Pology==
The simplest and best command-line method of translating gettext po-files with Apertium is by using the Python package [http://techbase.kde.org/Localization/Tools/Pology#About Pology]. Follow the instructions on the link to set it up, then do something like:
The simplest and best command-line method of translating gettext po-files with Apertium is by using the Python package [http://techbase.kde.org/Localization/Tools/Pology#About Pology].

Follow the instructions on the link to set it up, it should be something like:
<pre>
svn checkout svn://anonsvn.kde.org/home/kde/trunk/l10n-support/pology
</pre>
and put <pre>export PATH=POLOGYDIR/bin:$PATH
export PYTHONPATH=POLOGYDIR:$PYTHONPATH</pre>
in your ~/.bashrc (exchanging POLOGYDIR for the directory you checked it out to).

Then, in a new terminal, you can do:
<pre>
<pre>
$ pomtrans -s en -t es apertium es.po
$ pomtrans -s en -t es apertium es.po
Line 12: Line 24:
</pre>
</pre>


In case you want to use a mode that's not named like "sl-tl", like "nb-nn_a", use the -M option:
In case you want to use a mode that's not named like "sl-tl", like "nob-nno", use the -M option:
<pre>
<pre>
$ pomtrans -s nb -t nn -p nn.:nb. -M nb-nn_a apertium nn.po
$ pomtrans -s nb -t nn -p nn.:nb. -M nob-nno apertium nn.po
</pre>
</pre>
(this again assumes that there's an nb.po file in the same directory)
(this again assumes that there's an nb.po file in the same directory)
Line 20: Line 32:
You might also want to specify the path to apertium (eg. if you installed apertium in /usr/local, not /usr), and the [http://translate.sourceforge.net/wiki/guide/translation/accelerators accelerator Key]; the full command then becomes:
You might also want to specify the path to apertium (eg. if you installed apertium in /usr/local, not /usr), and the [http://translate.sourceforge.net/wiki/guide/translation/accelerators accelerator Key]; the full command then becomes:
<pre>
<pre>
$ pomtrans -s nb -t nn -p nn.:nb. -M nb-nn_a -T /usr/local/bin/apertium -a "&" apertium nn.po
$ pomtrans -s nb -t nn -p nn.:nb. -M nob-nno -T /usr/local/bin/apertium -a "&" apertium nn.po
</pre>
</pre>


Line 28: Line 40:
'''Note''': all these pomtrans-examples assume that both the source and language files exist. So in the above examples, da.po and nn.po would have to exist even though it makes most sense to run MT when all msgstr's are empty. If you only have e.g. sv.po and need an empty da.po for pomtrans to fill with machine translations, you can first run
'''Note''': all these pomtrans-examples assume that both the source and language files exist. So in the above examples, da.po and nn.po would have to exist even though it makes most sense to run MT when all msgstr's are empty. If you only have e.g. sv.po and need an empty da.po for pomtrans to fill with machine translations, you can first run
<pre>msgfilter --keep-header -i sv.po -o da.po awk -e '{}'</pre>
<pre>msgfilter --keep-header -i sv.po -o da.po awk -e '{}'</pre>
(just remember to edit the header afterwards so it has the right language code).
(just remember to edit the header afterwards so it has the right language code). The program <code>msgfilter</code> is part of the <code>gettext</code> package (easily installable in all major package managers).

==slpo==
http://mbjnet.dk/slpo/ has a function to translate Gettext *.po files with apertium.
Using it is very simple. E.g. the command:

APERTIUM_LANGS="en-es" slpo -o mutt-es.po apertium mutt.pot

would translate a pot file for the Mutt mail user agent from English to Spanish and write
the result to the file "mutt-es.po". I.e. you set the language pair in an environment variable,
"APERTIUM_LANGS". You can also set it in a configuration file. Of course the language pair to be
used must be installed. You can check for installed language pairs with the command, "apertium -l".

In the case above, all the msgstrs will first be pre-filled with the contents of the msgids, i.e.
the original source messages, and then translated with apertium.

Slpo can do more with apertium. Please have a look at http://mbjnet.dk/slpo/README.slpo.


==pospell==
==pospell==
Line 51: Line 79:
$ cat sv.po | apertium-po sv-da > da.po
$ cat sv.po | apertium-po sv-da > da.po
</pre>
</pre>



==Virtaal==
==Virtaal==
Line 59: Line 86:
* [[Format handling]]
* [[Format handling]]
* [https://github.com/rory/apertium-po-l10n apertium-po-l10n] by Rory McCann, [http://www.technomancy.org/language/apertium-auto-translate-gettext/ described here]
* [https://github.com/rory/apertium-po-l10n apertium-po-l10n] by Rory McCann, [http://www.technomancy.org/language/apertium-auto-translate-gettext/ described here]
* [[Tips for translators]]


[[Category:Tools]]
[[Category:Tools]]

Latest revision as of 13:03, 25 November 2019

En français

Apertium does not have a built-in format handler for gettext / .po-files; however, there are excellent tools available which can use Apertium to translate these files. For command-line and batch usage, Pology is recommended; if you want Apertium to give suggestions in a po-editor, try Virtaal.

Pology[edit]

The simplest and best command-line method of translating gettext po-files with Apertium is by using the Python package Pology.

Follow the instructions on the link to set it up, it should be something like:

svn checkout svn://anonsvn.kde.org/home/kde/trunk/l10n-support/pology

and put

export PATH=POLOGYDIR/bin:$PATH
export PYTHONPATH=POLOGYDIR:$PYTHONPATH

in your ~/.bashrc (exchanging POLOGYDIR for the directory you checked it out to).

Then, in a new terminal, you can do:

 $ pomtrans -s en -t es apertium es.po 

This assumes the source language of es.po is "en". However, you might want to translate from Swedish to Danish using the files sv.po and da.po. In that case, you need to supply the "-p" argument:

 $ pomtrans -s sv -t da -p sv.:da. apertium da.po

In case you want to use a mode that's not named like "sl-tl", like "nob-nno", use the -M option:

 $ pomtrans -s nb -t nn -p nn.:nb. -M nob-nno apertium nn.po

(this again assumes that there's an nb.po file in the same directory)

You might also want to specify the path to apertium (eg. if you installed apertium in /usr/local, not /usr), and the accelerator Key; the full command then becomes:

 $ pomtrans -s nb -t nn -p nn.:nb. -M nob-nno -T /usr/local/bin/apertium -a "&" apertium nn.po

pomtrans can also work recursively on directories, and will mark any MT output as fuzzy, while skipping already-translated text. See the docs/user/lingo.docbook for some excellent documentation.


Note: all these pomtrans-examples assume that both the source and language files exist. So in the above examples, da.po and nn.po would have to exist even though it makes most sense to run MT when all msgstr's are empty. If you only have e.g. sv.po and need an empty da.po for pomtrans to fill with machine translations, you can first run

msgfilter --keep-header  -i sv.po -o da.po awk -e '{}'

(just remember to edit the header afterwards so it has the right language code). The program msgfilter is part of the gettext package (easily installable in all major package managers).

slpo[edit]

http://mbjnet.dk/slpo/ has a function to translate Gettext *.po files with apertium. Using it is very simple. E.g. the command:

   APERTIUM_LANGS="en-es" slpo -o mutt-es.po apertium mutt.pot

would translate a pot file for the Mutt mail user agent from English to Spanish and write the result to the file "mutt-es.po". I.e. you set the language pair in an environment variable, "APERTIUM_LANGS". You can also set it in a configuration file. Of course the language pair to be used must be installed. You can check for installed language pairs with the command, "apertium -l".

In the case above, all the msgstrs will first be pre-filled with the contents of the msgids, i.e. the original source messages, and then translated with apertium.

Slpo can do more with apertium. Please have a look at http://mbjnet.dk/slpo/README.slpo.

pospell[edit]

A combination of pospell and Apertium can also be used to translate gettext .po files.

I had some trouble with this when I tried, pology worked perfectly however. --unhammer 08:44, 15 September 2010 (UTC)

pospell is part of the spellutils package, available through apt-get, macports, emerge, urpmi...

Example[edit]

$ cat sv.po | pospell -n - -f -p apertium -- sv-da -u > da.po

Thus if you put

#!/bin/sh
pospell -n - -f -p apertium -- -u "$@"

into a file called eg. "apertium-po", and chmod +x apertium-po, you can do

$ cat sv.po | apertium-po sv-da > da.po

Virtaal[edit]

Or you could just use the .po file editor Virtaal, which has an Apertium plugin. (So far this only works with the web service, but later version might be able to use local installations.)

See also[edit]