Class Intl

java.lang.Object
org.javagi.util.Intl

@NullMarked public class Intl extends Object
Utility class to translate text to the current locale using GNU Gettext.

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.