For this I also created a custom TranslationService, as the default BundleTranslationProvider is getting the BundleLocalization by calling ServicesActivator.getDefault().getLocalizationService() instead of getting it injected.
So there are some questions on the BundleTranslationProvider API:
1. Should it be possible for a user to simply extend the BundleTranslationProvider? (it is located in an internal package)
2. Should retrieving the BundleLocalization be modified to get injected instead of calling the ServicesActivator? (not sure if this would have impact in other cases)
3. Should we modify the visibility of getBundle() to protected so it is easier to extend? Or should this even be changed to use the ResourceBundleHelper to avoid duplicated code?
I think the BundleTranslationProvider could simply be changed to look like this.
@Inject
BundleLocalization localizationService;
@Override
public String translate(String key, String contributorURI) {
if (localizationService == null)
return key;
ResourceBundle resourceBundle = ResourceBundleHelper.getResourceBundleForUri(contributorURI,
ResourceBundleHelper.toLocale(locale), localizationService);
return getResourceString(key, resourceBundle);
}
In that case it shouldn't be necessary to override it in most of the cases. But I'm not sure if this would have any side effects.
Because of the current development state, I wanted to ask about this first on the mailing list, before I contribute a patch via Gerrit. Any feedback is welcome!
Greez,
Dirk