public abstract class GettextResource extends ResourceBundle
Using the GNU gettext approach, compiled message catalogs are normal Java ResourceBundle classes and are thus interoperable with standard ResourceBundle based code.
The main differences between the Sun ResourceBundle approach and the GNU gettext approach are:
\
unnnn
syntax. Very few editors
can natively display international characters in this format. In the
GNU gettext approach, the translation files are called
"Resource.locale.po"
and are in the encoding the translator has chosen. Many editors
can be used. There are at least three GUI translating tools
(Emacs PO mode, KDE KBabel, GNOME gtranslator).
ResourceBundle.getString
throws a
MissingResourceException
when no translation is found.
In the GNU gettext approach, the gettext
function
returns the (English) message key in that case.
ngettext
function.
To compile GNU gettext message catalogs into Java ResourceBundle classes,
the msgfmt
program can be used.
ResourceBundle.Control
Modifier and Type | Field and Description |
---|---|
static boolean |
verbose |
parent
Constructor and Description |
---|
GettextResource() |
Modifier and Type | Method and Description |
---|---|
static String |
gettext(ResourceBundle catalog,
String msgid)
Returns the translation of msgid.
|
static String |
ngettext(ResourceBundle catalog,
String msgid,
String msgid_plural,
long n)
Returns the plural form for n of the translation of
msgid.
|
static String |
npgettext(ResourceBundle catalog,
String msgctxt,
String msgid,
String msgid_plural,
long n)
Returns the plural form for n of the translation of
msgid in the context of msgctxt.
|
static String |
pgettext(ResourceBundle catalog,
String msgctxt,
String msgid)
Returns the translation of msgid in the context of
msgctxt.
|
clearCache, clearCache, containsKey, getBaseBundleName, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getKeys, getLocale, getObject, getString, getStringArray, handleGetObject, handleKeySet, keySet, setParent
public static String gettext(ResourceBundle catalog, String msgid)
catalog
- a ResourceBundlemsgid
- the key string to be translated, an ASCII stringpublic static String ngettext(ResourceBundle catalog, String msgid, String msgid_plural, long n)
catalog
- a ResourceBundlemsgid
- the key string to be translated, an ASCII stringmsgid_plural
- its English plural formpublic static String pgettext(ResourceBundle catalog, String msgctxt, String msgid)
catalog
- a ResourceBundlemsgctxt
- the context for the key string, an ASCII stringmsgid
- the key string to be translated, an ASCII stringpublic static String npgettext(ResourceBundle catalog, String msgctxt, String msgid, String msgid_plural, long n)
catalog
- a ResourceBundlemsgctxt
- the context for the key string, an ASCII stringmsgid
- the key string to be translated, an ASCII stringmsgid_plural
- its English plural form