9.11.4 Style rules for PO files

The same style file can be used for styling of a PO file, for terminal output and for HTML output. It is written in CSS (Cascading Style Sheet) syntax. See https://www.w3.org/TR/css2/cover.html for a formal definition of CSS. Many HTML authoring tutorials also contain explanations of CSS.

In the case of HTML output, the style file is embedded in the HTML output. In the case of text output, the style file is interpreted by the msgcat program. This means, in particular, that when @import is used with relative file names, the file names are

  • - relative to the resulting HTML file, in the case of HTML output,
  • - relative to the style sheet containing the @import, in the case of text output. (Actually, @imports are not yet supported in this case, due to a limitation in libcroco.)

CSS rules are built up from selectors and declarations. The declarations specify graphical properties; the selectors specify when they apply.

In PO files, the following simple selectors (based on "CSS classes", see the CSS2 spec, section 5.8.3) are supported.

  • Selectors that apply to entire messages:
    .header

    This matches the header entry of a PO file.

    .translated

    This matches a translated message.

    .untranslated

    This matches an untranslated message (i.e. a message with empty translation).

    .fuzzy

    This matches a fuzzy message (i.e. a message which has a translation that needs review by the translator).

    .obsolete

    This matches an obsolete message (i.e. a message that was translated but is not needed by the current POT file any more).

  • Selectors that apply to parts of a message in PO syntax. Recall the general structure of a message in PO syntax:
    white-space
    #  translator-comments
    #. extracted-comments
    #: reference…
    #, flag…
    #| msgid previous-untranslated-string
    msgid untranslated-string
    msgstr translated-string
    .comment

    This matches all comments (translator comments, extracted comments, source file reference comments, flag comments, previous message comments, as well as the entire obsolete messages).

    .translator-comment

    This matches the translator comments.

    .extracted-comment

    This matches the extracted comments, i.e. the comments placed by the programmer at the attention of the translator.

    .reference-comment

    This matches the source file reference comments (entire lines).

    .reference

    This matches the individual source file references inside the source file reference comment lines.

    .flag-comment

    This matches the flag comment lines (entire lines).

    .flag

    This matches the individual flags inside flag comment lines.

    .fuzzy-flag

    This matches the ‘fuzzy’ flag inside flag comment lines.

    .previous-comment

    This matches the comments containing the previous untranslated string (entire lines).

    .previous

    This matches the previous untranslated string including the string delimiters, the associated keywords (msgid etc.) and the spaces between them.

    .msgid

    This matches the untranslated string including the string delimiters, the associated keywords (msgid etc.) and the spaces between them.

    .msgstr

    This matches the translated string including the string delimiters, the associated keywords (msgstr etc.) and the spaces between them.

    .keyword

    This matches the keywords (msgid, msgstr, etc.).

    .string

    This matches strings, including the string delimiters (double quotes).

  • Selectors that apply to parts of strings:
    .text

    This matches the entire contents of a string (excluding the string delimiters, i.e. the double quotes).

    .escape-sequence

    This matches an escape sequence (starting with a backslash).

    .format-directive

    This matches a format string directive (starting with a ‘%’ sign in the case of most programming languages, with a ‘{’ in the case of java-format and csharp-format, with a ‘~’ in the case of lisp-format and scheme-format, or with ‘$’ in the case of sh-format).

    .invalid-format-directive

    This matches an invalid format string directive.

    .added

    In an untranslated string, this matches a part of the string that was not present in the previous untranslated string. (Not yet implemented in this release.)

    .changed

    In an untranslated string or in a previous untranslated string, this matches a part of the string that is changed or replaced. (Not yet implemented in this release.)

    .removed

    In a previous untranslated string, this matches a part of the string that is not present in the current untranslated string. (Not yet implemented in this release.)

These selectors can be combined to hierarchical selectors. For example,

.msgstr .invalid-format-directive { color: red; }

will highlight the invalid format directives in the translated strings.

In text mode, pseudo-classes (CSS2 spec, section 5.11) and pseudo-elements (CSS2 spec, section 5.12) are not supported.

The declarations in HTML mode are not limited; any graphical attribute supported by the browsers can be used.

The declarations in text mode are limited to the following properties. Other properties will be silently ignored.

color (CSS2 spec, section 14.1)

background-color (CSS2 spec, section 14.2.1)

These properties is supported. Colors will be adjusted to match the terminal’s capabilities. Note that many terminals support only 8 colors.
font-weight (CSS2 spec, section 15.2.3)
This property is supported, but most terminals can only render two different weights: normal and bold. Values >= 600 are rendered as bold.
font-style (CSS2 spec, section 15.2.3)
This property is supported. The values italic and oblique are rendered the same way.
text-decoration (CSS2 spec, section 16.3.1)
This property is supported, limited to the values none and underline.