www.delorie.com/gnu/docs/gettext/gettext_225.html   search  
Buy GNU books!

GNU gettext utilities

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.5.10 Java

java, java2

File extension

String syntax

gettext shorthand

gettext/ngettext functions
GettextResource.gettext, GettextResource.ngettext

---, use ResourceBundle.getResource instead

---, use CLASSPATH instead



Use or emulate GNU gettext
---, uses a Java specific message catalog format

xgettext -k_

Formatting with positions
MessageFormat.format "{1,number} {0,number}"

fully portable

po-mode marking

Before marking strings as internationalizable, uses of the string concatenation operator need to be converted to MessageFormat applications. For example, "file "+filename+" not found" becomes MessageFormat.format("file {0} not found", new Object[] { filename }). Only after this is done, can the strings be marked and extracted.

GNU gettext uses the native Java internationalization mechanism, namely ResourceBundles. To convert a PO file to a ResourceBundle, the msgfmt program can be used with the option --java or --java2. To convert a ResourceBundle back to a PO file, the msgunfmt program can be used with the option --java.

Two different programmatic APIs can be used to access ResourceBundles. Note that both APIs work with all kinds of ResourceBundles, whether GNU gettext generated classes, or other .class or .properties files.

  1. The java.util.ResourceBundle API.

    In particular, its getString function returns a string translation. Note that a missing translation yields a MissingResourceException.

    This has the advantage of being the standard API. And it does not require any additional libraries, only the msgfmt generated .class files. But it cannot do plural handling, even if the resource was generated from a PO file with plural handling.

  2. The gnu.gettext.GettextResource API.

    Reference documentation in Javadoc 1.1 style format is in the javadoc1 directory and in Javadoc 2 style format in the javadoc2 directory.

    Its gettext function returns a string translation. Note that when a translation is missing, the msgid argument is returned unchanged.

    This has the advantage of having the ngettext function for plural handling.

    To use this API, one needs the libintl.jar file which is part of the GNU gettext package and distributed under the LGPL.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003