Difference between revisions of "Translating mnemonic files"
(Creating page) |
(Link to French page) |
||
Line 1: | Line 1: | ||
[[Traduction des fichiers mnémoniques|En français]] |
|||
Mnemonic files are an alternative to <code>.po</code> files to generate multilingual user interfaces. |
Mnemonic files are an alternative to <code>.po</code> files to generate multilingual user interfaces. |
||
Revision as of 10:32, 6 October 2014
Mnemonic files are an alternative to .po
files to generate multilingual user interfaces.
Except for the possible comments (starting with #) at the beginning of a file, the mnemonic files is made of lines with the following format:
Mnemonic "formatted_string_for_printf"
In these lines, the mnemonic (starting on the first column) must be kept unchanged from a language to another, while the string farther to the right is translated.
However, a string to be translated can contain the sequences \r
or \n
or other similar ones which, not only should not be translated, but must not disturb the translation of the following word when it touches the letter having a special meaning.
Similarly, indications of format as %s
, %3d
, %4.2f
... are kept unchanged.
Mnemonic files format is not directly carried out by Apertium package. It is necessary to recover the package apertium-c-formatters to have a deformatter which takes into account specificities of this format.
Contents
Getting and installing apertium-c-formatters package
If you did not already recover apertium-c-formatters package for translating man pages, let start by making the following operations:
Download apertium-c-formatters from SVN:
svn checkout http://apertium.svn.sourceforge.net/svnroot/apertium/trunk/apertium-c-formatters
Compile the source files:
make
Yes, compilation is very simple, and fast!
Install the tools:
make install
The above command assumes you have write access to /usr/local/bin
and /usr/local/share/man
. If not, enter the command:
sudo make install
By defaut, as for lttoolbox, apertium, and the language pairs, the installation is done in /usr/local/bin
and /usr/local/share
. If you wish to change the installation directory, you will have to change the first line of the makefile.
install_dir=/usr/local
will be replaced by the parent directory where the executable commands will be. For example, if you put:
install_dir=/usr
tools will be installed in /usr/bin
and man pages in /usr/share/man
.
Using
Available tools
Available tools to translate the mnemonic files are the following:
- desmnemo : deformatter for mnemonic files,
- remnemo : generic reformatter used for mnemonic files,
- apertium-mnemo : a shell intended to make the translation of mnemonic files easier.
Translation by calling the various tools
Assuming we are in the directory samples-mnemo
of the package apertium-c-formatter and we want to translate into Spanish the file mess-libremail.en
We can type:
cat mess-libremail.en | desmnemo | apertium -f none en-es | remnemo > mess-libremail.es-utf
If the source language was not English, we could first notice that we translate a mnemonic file using UTF-8 charset. If the file format is encoded ISO-8859-n (or any other character set), we need to convert the data into UTF-8 to make them compatible with Apertium, which will also provide a result UTF-8 encoded.
In addition, the command apertium
is executed with the -f none
option, which is necessary for the deformatter apertium-destxt
not to be used.
We can also give file names as parameters of the deformatter and the reformatter:
desmnemo mess-libremail.en | apertium -f none en-es | remnemo - mess-libremail.es-utf
We can notice the dash -
as the first parameter of remnemo
. Reformatters usually use the standard input (in this case the result produced by the command apertium
) whereas it can be useful to preserve the result of reformatting in a file. But the problem is the general syntax of apertium reformatters require to specify the output file as the 2nd parameter. The -
as the first parameter permit to overcome this problem.
More simple with the command apertium-mnemo
When a data format is integrated directly into the apertium
command, there is the -f
option to translate data produced in this format without having to call "by hand" a deformatter and a reformatter. The command apertium-mnemo
is a shell which permits to do in the same way.
For example, to translate into Esperanto the file mess-libremail.en
, we can type:
cat mess-libremail.en | apertium-mnemo en-eo > mess-libremail.es-utf
or even better:
apertium-mnemo en-eo mess-libremail.en mess-libremail.es-utf
The options -u
and -d datadir
of the command apertium
are caried out by apertium-mnemo
. You just have place them before the parameter indicating the translation direction (as for the command apertium
).