Johnride
Johnride

Reputation: 8746

Avoid .properties files GNU Gettext java

First, my issue is similar to those two :

JAVA gettext commons

error reading .po file in java

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!

Upvotes: 4

Views: 1449

Answers (1)

Johnride
Johnride

Reputation: 8746

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

Upvotes: 6

Related Questions