Reputation: 843
Is there a way to retrieve all localized messages for a given locale in Play 2 Framework with Java? There seems to be API for Scala, but not for Java.
If there is no official API, what's the best way to do it?
Upvotes: 0
Views: 595
Reputation: 55798
Atually I'd ... separate them, I'd keep views/controller messages in common Play path but i18n file I prefer to keep in separate JS/JSON file.
Of course I don't know specification of your project but we have several hundreds of labels in project and only ~ 20 of them are for JS, so there's no reason to load something which won't be used ever.
On the other hand it's just lighter for Play to serve public static, then read it and converting to JSON each time.
Upvotes: 0
Reputation: 843
Found nothing better then:
Properties prop = new Properties();
prop.load(play.Play.application().resourceAsStream("messages"));
return ok(Json.toJson(prop)).as("application/json");
Upvotes: 1