Class PoFile

java.lang.Object
ch.autumo.ui.utils.PoFile

public final class PoFile extends Object
A minimal gettext PO reader.

Understood: msgctxt, msgid, msgstr, continuation lines, the usual C escapes (including octal), comments, references, #, fuzzy entries and the file header entry. Not understood: plural forms (msgid_plural / msgstr[n]); the singular translation msgstr[0] is used if present.

The lookup key is msgctxt + '\0' + msgid, or just the msgid when there is no context (see key(String, String)). Entries with an empty translation or flagged fuzzy are dropped, which is exactly gettext's fallback behaviour: use the source text.

  • Field Details

    • CONTEXT_SEPARATOR

      public static final char CONTEXT_SEPARATOR
      Separator between the optional message context and the message id in a lookup key.
      See Also:
  • Method Details

    • parse

      public static Map<String,String> parse(String text) throws IOException
      Parses a PO document.
      Parameters:
      text - PO document
      Returns:
      lookup key - translation (untranslated and fuzzy entries left out)
      Throws:
      IOException - on a read error
    • key

      public static String key(String context, String id)
      Builds the lookup key for a message, using context only when it is set.
      Parameters:
      context - message context (may be null or empty)
      id - message id
      Returns:
      the lookup key, or id when no context is set