Locale::Po4a::TeX(3pm) | Po4a Tools | Locale::Po4a::TeX(3pm) |
Locale::Po4a::TeX - convert TeX documents and derivatives from/to PO files
The po4a (PO for anything) project goal is to ease translations (and more interestingly, the maintenance of translations) using gettext tools on areas where they were not expected like documentation.
Locale::Po4a::TeX is a module to help the translation of TeX documents into other [human] languages. It can also be used as a base to build modules for TeX-based documents.
Users should probably use the LaTeX module, which inherits from the TeX module and contains the definitions of common LaTeX commands.
This module can be used directly to handle generic TeX documents. This will split your document in smaller blocks (paragraphs, verbatim blocks, or even smaller like titles or indexes).
There are some options (described in the next section) that can customize this behavior. If this doesn't fit to your document format you're encouraged to write your own derivative module from this, to describe your format's details. See the section WRITING DERIVATIVE MODULES below, for the process description.
This module can also be customized by lines starting with "% po4a:" in the TeX file. This process is described in the INLINE CUSTOMIZATION section.
These are this module's particular options:
Note that there is a difference between verbatim and no_wrap environments. There is no command and comments analysis in verbatim blocks.
If this environment was not already registered, po4a will consider that this environment does not take any parameters.
If this environment was not already registered, po4a will consider that this environment does not take any parameters.
Use these options to override the default behavior of the defined commands.
The TeX module can be customized with lines starting by % po4a:. These lines are interpreted as commands to the parser. The following commands are recognized:
You can precede the command1 command by
Note: In this case you don't have to specify which parameters are translatable, but po4a must know the type and number of parameters.
The parameters argument is a set of [] (to indicate an
optional argument) or {} (to indicate a mandatory argument). You can place
an underscore (_) between these brackets to indicate that the parameter must
be translated. For example:
% po4a: command *chapter [_]{_}
This indicates that the chapter command has two parameters: an
optional (short title) and a mandatory one, which must both be translated.
If you want to specify that the href command has two mandatory parameters,
that you don't want to translate the URL (first parameter), and that you
don't want this command to be separated from its paragraph (which allow the
translator to move the link in the sentence), you can use:
% po4a: command -href {}{_}
In this case, the information indicating which arguments must be translated is only used if a paragraph is only composed of this href command.
As for the commands, env can be preceded by a plus (+) to indicate that the \begin command must be translated with all its arguments.
The regular expression is delimited by quotes. It should not create any back-reference. You should use (?:) if you need a group. It may also need some escapes.
For example, the LaTeX module uses the "(?:&|\\\\)" regular expression to translate separately each cell of a table (lines are separated by '\\' and cells by '&').
The notion of environment is expanded to the type displayed in the PO file. This can be used to split on "\\\\" in the first mandatory argument of the title command. In this case, the environment is title{#1}.
If this environment was not already registered, po4a will consider that this environment does not take any parameters.
Comments of a paragraph are inserted as a PO comment for the first translated string of this paragraph.
If a function is defined in %translate_buffer_env for the current environment, this function will be used to translate the buffer instead of translate_buffer().
Except from the file inclusion part, it is a cut and paste from Transtractor's read.
See the INLINE CUSTOMIZATION section for more details.
Command and environment functions take the following arguments (in addition to the $self object):
The first 3 arguments are extracted by get_leading_command or get_trailing_command.
Command and environment functions return the translation of the command with its arguments and a new environment.
Environment functions are called when a \begin command is found. They are called with the \begin command and its arguments.
The TeX module only proposes one command function and one environment function: generic_command and generic_environment.
generic_command uses the information specified by
register_generic_command or by adding definition to the TeX file:
% po4a: command command1 parameters
generic_environment uses the information specified by
register_generic_environment or by adding definition to the TeX file:
% po4a: environment env parameters
Both functions will only translate the parameters that were specified as translatable (with a '_'). generic_environment will append the name of the environment to the environment stack and generic_command will append the name of the command followed by an identifier of the parameter (like {#7} or [#2]).
This module needs more tests.
It was tested on a book and with the Python documentation.
Various points are tagged FIXME in the source.
Locale::Po4a::LaTeX(3pm), Locale::Po4a::TransTractor(3pm), po4a(7)
Nicolas François <nicolas.francois@centraliens.net>
Copyright © 2004, 2005 Nicolas FRANÇOIS <nicolas.francois@centraliens.net>.
This program is free software; you may redistribute it and/or modify it under the terms of GPL (see the COPYING file).
2023-01-03 | Po4a Tools |