.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Locale::Po4a::Xml 3pm" .TH Locale::Po4a::Xml 3pm "2023-01-03" "Po4a Tools" "Po4a Tools" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Locale::Po4a::Xml \- convert XML documents and derivates from/to PO files .SH "DESCRIPTION" .IX Header "DESCRIPTION" The po4a (\s-1PO\s0 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. .PP Locale::Po4a::Xml is a module to help the translation of \s-1XML\s0 documents into other [human] languages. It can also be used as a base to build modules for XML-based documents. .SH "TRANSLATING WITH PO4A::XML" .IX Header "TRANSLATING WITH PO4A::XML" This module can be used directly to handle generic \s-1XML\s0 documents. This will extract all tag's content, and no attributes, since it's where the text is written in most \s-1XML\s0 based documents. .PP 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 module derived from this, to describe your format's details. See the section \fB\s-1WRITING DERIVATE MODULES\s0\fR below, for the process description. .SH "OPTIONS ACCEPTED BY THIS MODULE" .IX Header "OPTIONS ACCEPTED BY THIS MODULE" The global debug option causes this module to show the excluded strings, in order to see if it skips something important. .PP These are this module's particular options: .IP "\fBnostrip\fR" 4 .IX Item "nostrip" Prevents it to strip the spaces around the extracted strings. .IP "\fBwrap\fR" 4 .IX Item "wrap" Canonicalizes the string to translate, considering that whitespaces are not important, and wraps the translated document. This option can be overridden by custom tag options. See the \fBtranslated\fR option below. .IP "\fBunwrap_attributes\fR" 4 .IX Item "unwrap_attributes" Attributes are wrapped by default. This option disables wrapping. .IP "\fBcaseinsensitive\fR" 4 .IX Item "caseinsensitive" It makes the tags and attributes searching to work in a case insensitive way. If it's defined, it will treat laNG and <\s-1BOOK\s0>Lang as lang. .IP "\fBescapequotes\fR" 4 .IX Item "escapequotes" Escape quotes in output strings. Necessary, for example, for creating string resources for use by Android build tools. .Sp See also: https://developer.android.com/guide/topics/resources/string\-resource.html .IP "\fBincludeexternal\fR" 4 .IX Item "includeexternal" When defined, external entities are included in the generated (translated) document, and for the extraction of strings. If it's not defined, you will have to translate external entities separately as independent documents. .IP "\fBontagerror\fR" 4 .IX Item "ontagerror" This option defines the behavior of the module when it encounters invalid \&\s-1XML\s0 syntax (a closing tag which does not match the last opening tag). It can take the following values: .RS 4 .IP "\fIfail\fR" 4 .IX Item "fail" This is the default value. The module will exit with an error. .IP "\fIwarn\fR" 4 .IX Item "warn" The module will continue, and will issue a warning. .IP "\fIsilent\fR" 4 .IX Item "silent" The module will continue without any warnings. .RE .RS 4 .Sp Be careful when using this option. It is generally recommended to fix the input file. .RE .IP "\fBtagsonly\fR" 4 .IX Item "tagsonly" Note: This option is deprecated. .Sp Extracts only the specified tags in the \fBtags\fR option. Otherwise, it will extract all the tags except the ones specified. .IP "\fBdoctype\fR" 4 .IX Item "doctype" String that will try to match with the first line of the document's doctype (if defined). If it doesn't, a warning will indicate that the document might be of a bad type. .IP "\fBaddlang\fR" 4 .IX Item "addlang" String indicating the path (e.g. ) of a tag where a lang=\*(L"...\*(R" attribute shall be added. The language will be defined as the basename of the \s-1PO\s0 file without any .po extension. .IP "\fBoptionalclosingtag\fR" 4 .IX Item "optionalclosingtag" Boolean indicating whether closing tags are optional (as in \s-1HTML\s0). By default, missing closing tags raise an error handled according to \fBontagerror\fR. .IP "\fBtags\fR" 4 .IX Item "tags" Note: This option is deprecated. You should use the \fBtranslated\fR and \fBuntranslated\fR options instead. .Sp Space-separated list of tags you want to translate or skip. By default, the specified tags will be excluded, but if you use the \*(L"tagsonly\*(R" option, the specified tags will be the only ones included. The tags must be in the form , but you can join some () to say that the content of the tag will only be translated when it's into a tag. .Sp You can also specify some tag options by putting some characters in front of the tag hierarchy. For example, you can put \fIw\fR (wrap) or \fIW\fR (don't wrap) to override the default behavior specified by the global \fBwrap\fR option. .Sp Example: W .IP "\fBattributes\fR" 4 .IX Item "attributes" Space-separated list of tag's attributes you want to translate. You can specify the attributes by their name (for example, \*(L"lang\*(R"), but you can prefix it with a tag hierarchy, to specify that this attribute will only be translated when it's in the specified tag. For example: <bbb><aaa>lang specifies that the lang attribute will only be translated if it's in an <aaa> tag, and it's in a <bbb> tag. .IP "\fBfoldattributes\fR" 4 .IX Item "foldattributes" Do not translate attributes in inline tags. Instead, replace all attributes of a tag by po4a\-id=<id>. .Sp This is useful when attributes shall not be translated, as this simplifies the strings for translators, and avoids typos. .IP "\fBcustomtag\fR" 4 .IX Item "customtag" Space-separated list of tags which should not be treated as tags. These tags are treated as inline, and do not need to be closed. .IP "\fBbreak\fR" 4 .IX Item "break" Space-separated list of tags which should break the sequence. By default, all tags break the sequence. .Sp The tags must be in the form <aaa>, but you can join some (<bbb><aaa>), if a tag (<aaa>) should only be considered when it's within another tag (<bbb>). .Sp Please note a tag should be listed in only one of the \fBbreak\fR, \fBinline\fR \&\fBplaceholder\fR, or \fBcustomtag\fR setting string. .IP "\fBinline\fR" 4 .IX Item "inline" Space-separated list of tags which should be treated as inline. By default, all tags break the sequence. .Sp The tags must be in the form <aaa>, but you can join some (<bbb><aaa>), if a tag (<aaa>) should only be considered when it's within another tag (<bbb>). .IP "\fBplaceholder\fR" 4 .IX Item "placeholder" Space-separated list of tags which should be treated as placeholders. Placeholders do not break the sequence, but the content of placeholders is translated separately. .Sp The location of the placeholder in its block will be marked with a string similar to: .Sp .Vb 1 \& <placeholder type=\e"footnote\e" id=\e"0\e"/> .Ve .Sp The tags must be in the form <aaa>, but you can join some (<bbb><aaa>), if a tag (<aaa>) should only be considered when it's within another tag (<bbb>). .IP "\fBbreak-pi\fR" 4 .IX Item "break-pi" By default, Processing Instructions (i.e., \f(CW\*(C`<? ... ?>\*(C'\fR tags) are handled as inline tags. Pass this option if you want the \s-1PI\s0 to be handled as breaking tag. Note that unprocessed \s-1PHP\s0 tags are handled as Processing Instructions by the parser. .IP "\fBnodefault\fR" 4 .IX Item "nodefault" Space separated list of tags that the module should not try to set by default in any category. .Sp If you have a tag which has its default setting by the subclass of this module but you want to set alternative setting, you need to list that tag as a part of the \fBnodefault\fR setting string. .IP "\fBcpp\fR" 4 .IX Item "cpp" Support C preprocessor directives. When this option is set, po4a will consider preprocessor directives as paragraph separators. This is important if the \s-1XML\s0 file must be preprocessed because otherwise the directives may be inserted in the middle of lines if po4a consider it belong to the current paragraph, and they won't be recognized by the preprocessor. Note: the preprocessor directives must only appear between tags (they must not break a tag). .IP "\fBtranslated\fR" 4 .IX Item "translated" Space-separated list of tags you want to translate. .Sp The tags must be in the form <aaa>, but you can join some (<bbb><aaa>), if a tag (<aaa>) should only be considered when it's within another tag (<bbb>). .Sp You can also specify some tag options by putting some characters in front of the tag hierarchy. This overrides the default behavior specified by the global \&\fBwrap\fR and \fBdefaulttranslateoption\fR option. .RS 4 .IP "\fIw\fR" 4 .IX Item "w" Tags should be translated and content can be re-wrapped. .IP "\fIW\fR" 4 .IX Item "W" Tags should be translated and content should not be re-wrapped. .IP "\fIi\fR" 4 .IX Item "i" Tags should be translated inline. .IP "\fIp\fR" 4 .IX Item "p" Tags should be translated as placeholders. .RE .RS 4 .Sp Internally, the \s-1XML\s0 parser only cares about these four options: \fIw\fR \fIW\fR \fIi\fR \fIp\fR. .Sp * Tags listed in \fBbreak\fR are set to \fIw\fR or \fIW\fR depending on the \fBwrap\fR option. .Sp * Tags listed in \fBinline\fR are set to \fIi\fR. .Sp * Tags listed in \fBplaceholder\fR are set to \fIp\fR. .Sp * Tags listed in \fBuntranslated\fR are without any of these options set. .Sp You can verify actual internal parameter behavior by invoking \fBpo4a\fR with \&\fB\-\-debug\fR option. .Sp Example: W<chapter><title> .Sp Please note a tag should be listed in either \fBtranslated\fR or \fBuntranslated\fR setting string. .RE .IP "\fBuntranslated\fR" 4 .IX Item "untranslated" Space-separated list of tags you do not want to translate. .Sp The tags must be in the form <aaa>, but you can join some (<bbb><aaa>), if a tag (<aaa>) should only be considered when it's within another tag (<bbb>). .Sp Please note a translatable inline tag in an untranslated tag is treated as a translatable breaking tag, \fIi\fR setting is dropped and \fIw\fR or \fIW\fR is set depending on the \fBwrap\fR option. .IP "\fBdefaulttranslateoption\fR" 4 .IX Item "defaulttranslateoption" The default categories for tags that are not in any of the translated, untranslated, break, inline, or placeholder. .Sp This is a set of letters as defined in \fBtranslated\fR and this setting is only valid for translatable tags. .SH "WRITING DERIVATIVE MODULES" .IX Header "WRITING DERIVATIVE MODULES" .SS "\s-1DEFINE WHAT TAGS AND ATTRIBUTES TO TRANSLATE\s0" .IX Subsection "DEFINE WHAT TAGS AND ATTRIBUTES TO TRANSLATE" The simplest customization is to define which tags and attributes you want the parser to translate. This should be done in the initialize function. First you should call the main initialize, to get the command-line options, and then, append your custom definitions to the options hash. If you want to treat some new options from command line, you should define them before calling the main initialize: .PP .Vb 6 \& $self\->{options}{\*(Aqnew_option\*(Aq}=\*(Aq\*(Aq; \& $self\->SUPER::initialize(%options); \& $self\->{options}{\*(Aq_default_translated\*(Aq}.=\*(Aq <p> <head><title>\*(Aq; \& $self\->{options}{\*(Aqattributes\*(Aq}.=\*(Aq <p>lang id\*(Aq; \& $self\->{options}{\*(Aq_default_inline\*(Aq}.=\*(Aq <br>\*(Aq; \& $self\->treat_options; .Ve .PP You should use the \fB_default_inline\fR, \fB_default_break\fR, \&\fB_default_placeholder\fR, \fB_default_translated\fR, \fB_default_untranslated\fR, and \fB_default_attributes\fR options in derivative modules. This allow users to override the default behavior defined in your module with command line options. .SS "\s-1OVERRIDE THE DEFAULT BEHAVIOR WITH COMMAND LINE OPTIONS\s0" .IX Subsection "OVERRIDE THE DEFAULT BEHAVIOR WITH COMMAND LINE OPTIONS" If you don't like the default behavior of this xml module and its derivative modules, you can provide command line options to change their behavior. .PP See \fBLocale::Po4a::Docbook\fR\|(3pm), .SS "\s-1OVERRIDING THE\s0 found_string \s-1FUNCTION\s0" .IX Subsection "OVERRIDING THE found_string FUNCTION" Another simple step is to override the function \*(L"found_string\*(R", which receives the extracted strings from the parser, in order to translate them. There you can control which strings you want to translate, and perform transformations to them before or after the translation itself. .PP It receives the extracted text, the reference on where it was, and a hash that contains extra information to control what strings to translate, how to translate them and to generate the comment. .PP The content of these options depends on the kind of string it is (specified in an entry of this hash): .ie n .IP "type=""tag""" 4 .el .IP "type=``tag''" 4 .IX Item "type=tag" The found string is the content of a translatable tag. The entry \*(L"tag_options\*(R" contains the option characters in front of the tag hierarchy in the module \&\*(L"tags\*(R" option. .ie n .IP "type=""attribute""" 4 .el .IP "type=``attribute''" 4 .IX Item "type=attribute" Means that the found string is the value of a translatable attribute. The entry \*(L"attribute\*(R" has the name of the attribute. .PP It must return the text that will replace the original in the translated document. Here's a basic example of this function: .PP .Vb 6 \& sub found_string { \& my ($self,$text,$ref,$options)=@_; \& $text = $self\->translate($text,$ref,"type ".$options\->{\*(Aqtype\*(Aq}, \& \*(Aqwrap\*(Aq=>$self\->{options}{\*(Aqwrap\*(Aq}); \& return $text; \& } .Ve .PP There's another simple example in the new Dia module, which only filters some strings. .SS "\s-1MODIFYING TAG TYPES\s0 (\s-1TODO\s0)" .IX Subsection "MODIFYING TAG TYPES (TODO)" This is a more complex one, but it enables a (almost) total customization. It's based on a list of hashes, each one defining a tag type's behavior. The list should be sorted so that the most general tags are after the most concrete ones (sorted first by the beginning and then by the end keys). To define a tag type you'll have to make a hash with the following keys: .IP "\fBbeginning\fR" 4 .IX Item "beginning" Specifies the beginning of the tag, after the \*(L"<\*(R". .IP "\fBend\fR" 4 .IX Item "end" Specifies the end of the tag, before the \*(L">\*(R". .IP "\fBbreaking\fR" 4 .IX Item "breaking" It says if this is a breaking tag class. A non-breaking (inline) tag is one that can be taken as part of the content of another tag. It can take the values false (0), true (1) or undefined. If you leave this undefined, you'll have to define the f_breaking function that will say whether a concrete tag of this class is a breaking tag or not. .IP "\fBf_breaking\fR" 4 .IX Item "f_breaking" It's a function that will tell if the next tag is a breaking one or not. It should be defined if the \fBbreaking\fR option is not. .IP "\fBf_extract\fR" 4 .IX Item "f_extract" If you leave this key undefined, the generic extraction function will have to extract the tag itself. It's useful for tags that can have other tags or special structures in them, so that the main parser doesn't get mad. This function receives a boolean that says if the tag should be removed from the input stream or not. .IP "\fBf_translate\fR" 4 .IX Item "f_translate" This function receives the tag (in the \fBget_string_until()\fR format) and returns the translated tag (translated attributes or all needed transformations) as a single string. .SH "INTERNAL FUNCTIONS used to write derivative parsers" .IX Header "INTERNAL FUNCTIONS used to write derivative parsers" .SS "\s-1WORKING WITH TAGS\s0" .IX Subsection "WORKING WITH TAGS" .IP "\fBget_path()\fR" 4 .IX Item "get_path()" This function returns the path to the current tag from the document's root, in the form <html><body><p>. .Sp An additional array of tags (without brackets) can be passed as argument. These path elements are added to the end of the current path. .IP "\fBtag_type()\fR" 4 .IX Item "tag_type()" This function returns the index from the tag_types list that fits to the next tag in the input stream, or \-1 if it's at the end of the input file. .Sp Here, the tag has structure started by < and end by > and it can contain multiple lines. .Sp This works on the array \f(CW\*(C`@{$self\->{TT}{doc_in}}\*(C'\fR holding input document data and reference indirectly via \f(CW\*(C`$self\->shiftline()\*(C'\fR and \f(CW\*(C`$self\->unshiftline($$)\*(C'\fR. .IP "extract_tag($$)" 4 .IX Item "extract_tag($$)" This function returns the next tag from the input stream without the beginning and end, in an array form, to maintain the references from the input file. It has two parameters: the type of the tag (as returned by tag_type) and a boolean, that indicates if it should be removed from the input stream. .Sp This works on the array \f(CW\*(C`@{$self\->{TT}{doc_in}}\*(C'\fR holding input document data and reference indirectly via \f(CW\*(C`$self\->shiftline()\*(C'\fR and \f(CW\*(C`$self\->unshiftline($$)\*(C'\fR. .IP "get_tag_name(@)" 4 .IX Item "get_tag_name(@)" This function returns the name of the tag passed as an argument, in the array form returned by extract_tag. .IP "\fBbreaking_tag()\fR" 4 .IX Item "breaking_tag()" This function returns a boolean that says if the next tag in the input stream is a breaking tag or not (inline tag). It leaves the input stream intact. .IP "\fBtreat_tag()\fR" 4 .IX Item "treat_tag()" This function translates the next tag from the input stream. Using each tag type's custom translation functions. .Sp This works on the array \f(CW\*(C`@{$self\->{TT}{doc_in}}\*(C'\fR holding input document data and reference indirectly via \f(CW\*(C`$self\->shiftline()\*(C'\fR and \f(CW\*(C`$self\->unshiftline($$)\*(C'\fR. .IP "tag_in_list($@)" 4 .IX Item "tag_in_list($@)" This function returns a string value that says if the first argument (a tag hierarchy) matches any of the tags from the second argument (a list of tags or tag hierarchies). If it doesn't match, it returns 0. Else, it returns the matched tag's options (the characters in front of the tag) or 1 (if that tag doesn't have options). .SS "\s-1WORKING WITH ATTRIBUTES\s0" .IX Subsection "WORKING WITH ATTRIBUTES" .IP "treat_attributes(@)" 4 .IX Item "treat_attributes(@)" This function handles the translation of the tags' attributes. It receives the tag without the beginning / end marks, and then it finds the attributes, and it translates the translatable ones (specified by the module option \fBattributes\fR). This returns a plain string with the translated tag. .SS "\s-1WORKING WITH TAGGED CONTENTS\s0" .IX Subsection "WORKING WITH TAGGED CONTENTS" .IP "\fBtreat_content()\fR" 4 .IX Item "treat_content()" This function gets the text until the next breaking tag (not inline) from the input stream. Translate it using each tag type's custom translation functions. .Sp This works on the array \f(CW\*(C`@{$self\->{TT}{doc_in}}\*(C'\fR holding input document data and reference indirectly via \f(CW\*(C`$self\->shiftline()\*(C'\fR and \f(CW\*(C`$self\->unshiftline($$)\*(C'\fR. .SS "\s-1WORKING WITH THE MODULE OPTIONS\s0" .IX Subsection "WORKING WITH THE MODULE OPTIONS" .IP "\fBtreat_options()\fR" 4 .IX Item "treat_options()" This function fills the internal structures that contain the tags, attributes and inline data with the options of the module (specified in the command-line or in the initialize function). .SS "\s-1GETTING TEXT FROM THE INPUT DOCUMENT\s0" .IX Subsection "GETTING TEXT FROM THE INPUT DOCUMENT" .IP "get_string_until($%)" 4 .IX Item "get_string_until($%)" This function returns an array with the lines (and references) from the input document until it finds the first argument. The second argument is an options hash. Value 0 means disabled (the default) and 1, enabled. .Sp The valid options are: .RS 4 .IP "\fBinclude\fR" 4 .IX Item "include" This makes the returned array to contain the searched text .IP "\fBremove\fR" 4 .IX Item "remove" This removes the returned stream from the input .IP "\fBunquoted\fR" 4 .IX Item "unquoted" This ensures that the searched text is outside any quotes .IP "\fBregex\fR" 4 .IX Item "regex" This denotes that the first argument is a regular expression rather than an plain string .RE .RS 4 .RE .IP "skip_spaces(\e@)" 4 .IX Item "skip_spaces(@)" This function receives as argument the reference to a paragraph (in the format returned by get_string_until), skips his heading spaces and returns them as a simple string. .IP "join_lines(@)" 4 .IX Item "join_lines(@)" This function returns a simple string with the text from the argument array (discarding the references). .SH "STATUS OF THIS MODULE" .IX Header "STATUS OF THIS MODULE" This module can translate tags and attributes. .SH "TODO LIST" .IX Header "TODO LIST" \&\s-1DOCTYPE\s0 (\s-1ENTITIES\s0) .PP There is a minimal support for the translation of entities. They are translated as a whole, and tags are not taken into account. Multilines entities are not supported and entities are always rewrapped during the translation. .PP \&\s-1MODIFY TAG TYPES FROM INHERITED MODULES\s0 (move the tag_types structure inside the \f(CW$self\fR hash?) .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBLocale::Po4a::TransTractor\fR\|(3pm), \&\fBpo4a\fR\|(7) .SH "AUTHORS" .IX Header "AUTHORS" .Vb 2 \& Jordi Vilalta <jvprat@gmail.com> \& Nicolas François <nicolas.francois@centraliens.net> .Ve .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" .Vb 2 \& Copyright © 2004 Jordi Vilalta <jvprat@gmail.com> \& Copyright © 2008\-2009 Nicolas François <nicolas.francois@centraliens.net> .Ve .PP This program is free software; you may redistribute it and/or modify it under the terms of \s-1GPL\s0 (see the \s-1COPYING\s0 file).