Question

First, my issue is similar to those two :

JAVA gettext commons

error reading .po file in java

  • I want to use GNU Gettext utility for internationnalizing my app. I managed to get it working by creating a translations.properties file with the proper key-value pair but it wont get my translations_fr_CA.properties even if I explicitly set the locale to fr_CA or Locale.CANADA_FRENCH. This was my first issue.

  • Second and most important issue : I can't get rid of the .properties file which is crap as I can't use the nice gettext complete msgid . I managed to compile my .po file to a .class with msgfmt --java2 [...] but the ResourceBundle won't load without a .properties file.

Here is a zip of my current testing project : java_gettext_testing.zip

I included gnu.gettext.GettextResource in the zip to make it simpler. You can compile with javac test/*.java and run with java test.test

Thanks for any help!

Was it helpful?

Solution

I figured it out finally. I don't know why but I cant use .class files without putting them in a package. I reworked my structure and finally I can compile my .po file with

msgfmt --java2 -d . -r test.translations translations.po

which will compile the ./translations.po file to test/translations.class giving it the appropriate package information.

Now I can do this

ResourceBundle myRes = ResourceBundle.getBundle("test.translations"); // load my test/translations.class file

GettextResource.gettext(myRes, "message id to translate");

Still got to get the locale working but the essential is there for me right now.

Edit This question helped me to understand that msgfmt was compiling .po files into "real" java objects How to use ResourceBundle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top