0

我们从我们的数据库中加载我们的翻译。要检索捆绑包,我们有一个自定义java.util.ResourceBundle.Control

为了翻译我们的 e4 RCP 应用程序,我已经创建了一个TranslationService,我使用插件将它添加到根上下文中。那没问题(只是我不得不复制 95% 的BundleTranslationProvider,因为我没有看到任何其他方式)。

现在我想使用新的消息扩展(Eclipse Luna 附带)来翻译其余部分。据我从默认MessageFactoryServiceImpl的来源可以看出,似乎也没有一种简单的方法可以在那里注入我的 ResourceBundle.Control 。

链接的博客系列中,描述了从数据库获取资源包的用例,但通过使用基于类的资源包来解决。这是没有选择的,因为我不能为每个资源包和每个语言环境实现一个类。从数据库加载资源包的原因是能够将翻译部署为语言,而无需重新部署应用程序。

是通过复制 99% 的默认MessageFactoryServiceImpl创建我自己的 IMessageFactoryService 来实现这一点的唯一方法,只是将我们的控制权传递给对 ResourceBundleHelper 的调用?

4

2 回答 2

1

After some investigation on this, I found a way that you are able to support your use case without modifying or copying code a lot.

You need to exchange the BundleLocalization to load the ResourceBundle your way. In your case by using your custom ResourceBundle.Control. By doing this you override that the platform is looking for the ResourceBundle specified by the MANIFEST.

At the moment you will also have to implement a custom TranslationService that uses your BundleLocalization. The existing BundleTranslationProvider does not take the BundleLocalization out of the context. And you will need to copy a lot of code there, because getBundle() is private. I will discuss possible modifications with the developers.

You can find an example here: https://github.com/fipro78/e4classbasedtranslation

Hope that helps you to solve your specific requirement.

于 2014-02-16T08:38:05.753 回答
1

AFAIK ResourceBundle.Control 用于加载 ResourceBundles。在新的消息扩展中,我们使用自定义 ResourceBundle.Control 来启用在 OSGi 上下文中加载资源包,并且它可以通过注释进行配置。

AFAICS 交换 ResourceBundle.Control 将破坏新消息扩展支持的任何其他用例。

问题是,为什么要使用自定义 ResourceBundle.Control 而不是创建基于类的 ResourceBundle?我还没有尝试过,但也许可以只创建基本 ResourceBundle(没有区域设置信息)并以不同于使用 getLocale() 的方式确定区域设置。

但是在不知道您在自定义 ResourceBundle.Control 中做什么的情况下,我不知道该回答什么以及建议什么。当然,我们可以为此打开 API,但正如我之前所说,使用默认实现的所有其他插件都会失败。

也许你可以给出一些关于你正在做什么的提示,我可以向你展示一种以另一种方式实现目标的方法。

于 2014-02-14T15:47:55.867 回答