Add internationalization utility class #281
No reviewers
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
java
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
java-gi/java-gi!281
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "i18n"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I've added a utility class to help translate Java-GI applications with GNU Gettext.
To use it, call
Intl.bindtextdomain()andIntl.textdomain()in your main method to set the domain (for example, the name of the app) and the directory where the translations (locale-specific.mofiles) are located. Then, pass all user-visible text messages toIntl.i18n(). This is all you need to do in your application source code.To create the translation files, follow these steps:
xgettext --keyword=i18non the Java source files. This will generate a.potfile..pofiles from it withmsginit..pofiles are checked into version control, and will be edited by translators..potfile changes later on, usemsgmergeto update the.pofiles..pofiles into binary.mofiles withmsgfmt. Make sure the.mofiles are in the standard directory structure:locale/<lang>/LC_MESSAGES/<textdomain>.mo. This directory is passed to thetextdomain()method mentioned above.Note: Gettext can work with Java ResourceBundles instead of
.mofiles, but this is not supported by this utility class. The reason is that.mofiles are required to translate strings in Gtk template class.uifiles, and it doesn't make much sense to put some messages in ResourceBundles and others in.mofiles.