简体   繁体   English

Eclipse RCP Internationalization独立插件

[英]Eclipse RCP Internationalization separate plugin

No tutorial presents a concrete example of how an internationalization plug-in fragment is created an used. 没有教程提供了如何创建国际化插件片段的具体示例。 I need translations to the plugin.xml 's and source code files. 我需要翻译到plugin.xml和源代码文件。 Trying to wrap my head around where the translations go, and where the i18n facade goes. 试着把头转过去翻译的地方,以及i18n门面的去处。

1. How does that fragment apply to an multi-plugin enterprise application, and more importantly, how do all those plugins externalize their strings inside appropriate folders in the fragment? 1.该片段如何应用于多插件企业应用程序,更重要的是,所有这些插件如何将其字符串外部化到片段中的相应文件夹中?

2. What about external JARs? 2. 外部JAR怎么样? How does the mechanism provide translation support for external resources? 该机制如何为外部资源提供翻译支持?

3. With the risk of being a long-shot, would it be possible to provide independent translation of a view or perspective ? 3.由于存在长期风险,是否有可能提供独立的viewperspective翻译? Not necessarily at runtime, because I know bundles can't be dynamically switched. 不一定是在运行时,因为我知道bundle无法动态切换。

There is some help available, this article lists the process. 有一些帮助, 本文列出了该过程。 It's based on Eclipse 2.0 (!) but the basic ideas are still correct. 它基于Eclipse 2.0(!),但基本思想仍然正确。 An even better article is this tutorial by Vogella Vogella的这篇教程是一篇更好的文章

  1. For each plugin you need to translate, you will create one plugin fragment. 对于您需要翻译的每个插件,您将创建一个插件片段。 The fragment is associated to one host plugin, so you need several fragments. 该片段与一个主机插件相关联,因此您需要多个片段。 Each fragment can contain several languages though. 每个片段可以包含多种语言。 The languages are separated by the folder structure as described in Step 5 in the first article 语言由文件夹结构分隔,如第一篇文章中的步骤5所述

  2. I am guessing you are referring to non-eclipse Java jars that you have made yourself, yes? 我猜你指的是你自己制作的非日食Java罐子,是吗? If so, that is a completly different process, best suited for a separate question with the Java tag. 如果是这样,那是一个完全不同的过程,最适合使用Java标记的单独问题。 Oracle has a guide that may help . Oracle有一个可能有用指南 But keep in mind that you only need to translate the content that the user is exposed to. 但请记住,您只需要翻译用户所接触的内容。 So a refactor to keep all user visible strings to the Eclipse plugins might be a good idea. 因此,将所有用户可见字符串保留在Eclipse插件中的重构可能是个好主意。

  3. Are you referring to the name of the view/perspective? 你指的是视图/透视的名称吗? If so, yes. 如果是的话,是的。 You can translate the information you give in your plugin.xml aswell. 您也可以翻译plugin.xml中提供的信息。 See Vogellas article, chapter 3 参见Vogellas的文章,第3章

Edit: 编辑:

At nr.3 I was referring to choosing which View to translate (eg via a view menu), then restart the app, then only the said view should translate

Well.. I think of a way that would work in theory, but I'm not sure its the best alternative. 嗯..我想到了一种理论上可行的方法,但我不确定它是最好的选择。 So translatation is based on locale. 所以翻译是基于语言环境。 And given the locale a certain translation is chosen. 并且根据区域设置选择一定的翻译。 If no appropriate translation exists, a default will be selected. 如果不存在适当的翻译,则将选择默认值。

So if your View menu were to change the locale of the application to, say "us-en-v1", and you only had one view which had a translation for the locale "us-en-v1", that would mean that particular view would be translated, but the rest of the application would use a default (could be that they default back to the closest translation, dont remember exactly). 因此,如果您的“视图”菜单要将应用程序的区域设置更改为“us-en-v1”,并且您只有一个视图具有区域设置“us-en-v1”的翻译,则这意味着特定的视图将被翻译,但应用程序的其余部分将使用默认值(可能是他们默认返回到最接近的翻译,不记得确切)。

Then for each view you would create a new translation and use a unique locale for each. 然后,对于每个视图,您将创建一个新的翻译并为每个视图使用唯一的区域设置。

That should work, but it abuses the way translations are supposed to work, so it could lead to issues. 这应该有效,但它会滥用翻译的工作方式,因此可能会导致问题。

I've done something similar at one time, one app was used in the same language but different customers had different vocabulary. 我曾经做过类似的事情,一个应用程序使用相同的语言,但不同的客户有不同的词汇。 So we used the i18n to make the application use the right terms by defining our own locales. 因此,我们使用i18n通过定义我们自己的语言环境使应用程序使用正确的术语。

We are using http://babel.eclipse.org/babel/ to let people translate existing ressources. 我们使用http://babel.eclipse.org/babel/让人们翻译现有的资源。 The build process adds the required language fragments to the artefact. 构建过程将所需的语言片段添加到人工制品中。 Each plug-in defines its own Messages.properties / Messages.java file. 每个插件都定义了自己的Messages.properties / Messages.java文件。 I guess, you can't do much about external jars. 我猜,你对外部罐子做的不多。

For instance: 例如:

public final class MyMessages {
  // a string member as you reference it later in the code 
  public static String login_window_user_label;

  // static initializer which initalizes the fields in this class
  static {
    NLS.initializeMessages("mymessages", MyMessages.class);
  }
}

And (usually in the same package) you have a properties file, in this case, 并且(通常在同一个包中)你有一个属性文件,在这种情况下,

mymessages.properties mymessages.properties

which includes the string: 其中包括字符串:

login_window_user_label = Enter username to login to {0}

And within the code you do: 在您执行的代码中:

String userNameLabel = NLS.bind(MyMessages.login_window_user_label, Environment.getName());

Thats how we make our bundles "translatable". 这就是我们如何使我们的捆绑“可翻译”。 The build generates the language fragments and the babel server instance allows the translation. 构建生成语言片段,babel服务器实例允许翻译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM