[errai-dev] Another i18n consideration...

Eric Wittmann eric.wittmann at redhat.com
Tue Apr 9 14:59:07 EDT 2013


I was working on the s-ramp browser UI some more today, and encountered 
a case where I need non-template translations.

I have a client-side only notification service (basically an 
@ApplicationScoped service that can be used to growl at the user).  When 
various application events occur, I will use the notification service to 
pop up a growl.  The title and message is different based on the 
context.  It's basically stuff like "Hey, I just did this for you." or 
"Oh no, something you did caused an error." or "Please wait while I do 
this thing for you...".

In these cases the growl widget is templated, but the title and body 
will be replaced with data passed in.  That data originates on the 
client-side but *not* from a template.

Some thoughts on possible ways to address this issue:

1) @Inject the TranslationService and simply call "translate" directly.
   a) ok great, but what key do I use, and how does that key get 
included in the bundle(s)?
   b) Create a new annotation to somehow indicate additional keys that 
should be translated, along with default values?

Something like this perhaps:

@ApplicationScoped
class MyService {
   @Inject @Translations({
     @Translation(key="growl-title", defaultValue="Hey Dude!"),
     @Translation(key="growl-message", defaultValue="This thing you care 
about just happened..."),
})
   private TranslationService translationService;

   public void someMethod() {
     String translatedValue =
        translationService.getTranslation("growl-title");
     // Do something with it
   }
}

Verbose but effective.  The bundle would then be generated to include 
MyService.growl-title and MyService.growl-message.

Thoughts?  Is there another way to solve this use case?

-Eric




More information about the errai-dev mailing list