我正在改变插件的语言环境,正如我在此处提到的那样:http://jaider.net/12-06-2011/how-to-internationalize-your-eclipse-plug-in/ 但是有一些组件需要刷新(如果它们是可见的),例如自定义视图(org.eclipse.ui.views)或Menu,以避免重启Eclipse。我需要你的帮助。
答案 0 :(得分:3)
该平台无法在运行时切换区域设置。 IExtensionRegistry
在加载视图的扩展时选择了一个区域设置,更新它们的唯一一般方法是重新启动。
org.eclipse.core.runtime.IExtensionRegistry
添加了新的多语言支持(可能在3.7.0?),但框架目前还没有使用它。
编辑:重启
要使用新的语言环境重新启动eclipse,您需要更改命令行(更新 -nl 标志),将其保存在系统属性eclipse.exitdata
中,然后退出{{ 1}}与IApplication
。有关如何使用此示例的示例,请参阅org.eclipse.equinox.app.IApplication.EXIT_RELAUNCH
。
答案 1 :(得分:1)
谢谢保罗。这里是用新语言重启的代码:
private static final String PROP_VM = "eclipse.vm"; //$NON-NLS-1$
private static final String PROP_VMARGS = "eclipse.vmargs"; //$NON-NLS-1$
private static final String PROP_COMMANDS = "eclipse.commands"; //$NON-NLS-1$
private static final String PROP_EXIT_CODE = "eclipse.exitcode"; //$NON-NLS-1$
private static final String PROP_EXIT_DATA = "eclipse.exitdata"; //$NON-NLS-1$
private static final String CMD_NL = "-nl"; //$NON-NLS-1$
private static final String CMD_VMARGS = "-vmargs"; //$NON-NLS-1$
private static final String NEW_LINE = "\n"; //$NON-NLS-1$
private static void restart(String nl) {
String command_line = buildCommandLine(nl);
if (command_line == null) {
return;
}
System.setProperty(PROP_EXIT_CODE, org.eclipse.equinox.app.IApplication.EXIT_RELAUNCH.toString());//Integer.toString(24)
System.setProperty(PROP_EXIT_DATA, command_line);
Workbench.getInstance().restart();
}
private static String buildCommandLine(String nl) {
String property = System.getProperty(PROP_VM);
StringBuffer result = new StringBuffer();
if (property != null) {
result.append(property);
}
result.append(NEW_LINE);
// append the vmargs and commands. Assume that these already end in \n
String vmargs = System.getProperty(PROP_VMARGS);
if (vmargs != null) {
result.append(vmargs);
}
// append the rest of the args, replacing or adding -data as required
property = System.getProperty(PROP_COMMANDS);
if (property != null) {// find the index of the arg to replace its value
int cmd_nl_pos = property.lastIndexOf(CMD_NL);
if (cmd_nl_pos != -1) {
cmd_nl_pos += CMD_NL.length() + 1;
result.append(property.substring(0, cmd_nl_pos));
result.append(nl);
result.append(property.substring(property.indexOf('\n',
cmd_nl_pos)));
} else {
result.append(NEW_LINE);
result.append(property);
result.append(NEW_LINE);
result.append(CMD_NL);
result.append(NEW_LINE);
result.append(nl);
}
}
// put the vmargs back at the very end (the eclipse.commands property
// already contains the -vm arg)
if (vmargs != null) {
result.append(CMD_VMARGS);
result.append(NEW_LINE);
result.append(vmargs);
}
return result.toString();
}