Class Intl
To use this class, call bindtextdomain and textdomain
at the start of your application, ideally at the top of your main()
method, but in any case before Gtk is initialized. For every text message
that is displayed to the users, call one of the i18n(String)
methods to retrieve a translation in the current locale. When no translation
is present, the original text is returned.
It is recommended to statically import the i18n(java.lang.String) methods in
all classes where it is used.
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", filename). Only after
this is done, can the strings be marked and extracted.
This class requires GNU Gettext to be installed. Specifically, it will try
to load the libgettextlib shared library. If that did not work, all
methods will silently fallback to return the original (English) messages.
Gettext offers tools to extract a message catalogue from your application sources and create and compile per-language translation files. Consult the GNU Gettext documentation for details.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable Stringbindtextdomain(String domainname, String dirname) Set directory containing message catalogs for Gettext.static StringTranslate the string.static StringTranslate a string with context.static StringTranslate a string that can be singular or plural.static @Nullable Stringtextdomain(String domainname) Set or retrieve the current text domain for Gettext.
-
Constructor Details
-
Intl
public Intl()
-
-
Method Details
-
bindtextdomain
Set directory containing message catalogs for Gettext.- Parameters:
domainname- the message domaindirname- the base directory of the hierarchy containing message catalogs fordomainname- Returns:
- the current base directory for domain
domainname, ornullif an error occured.
-
textdomain
-
i18n
-
i18n
Translate a string that can be singular or plural.- Parameters:
msgid- the string to translateplural- the string to translate (plural form)n- determines whether singular or plural translation is chosen- Returns:
- the translation, or
msgidorpluralif none is found - See Also:
-
i18n
-