1.resources目录新增国际化资源文件
我项目默认英文,增加了一个zh中文的,en-英语 cn-中文
2.参数定义,中文需转为Unicode编码,推荐Unicode编码转换 - 站长工具 (chinaz.com)
3.新增类CodeChronoBundle继承AbstractBundle
package com.codechrono.idea.plugin.utils;
import com.intellij.AbstractBundle;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.PropertyKey;
import java.util.Locale;
public final class CodeChronoBundle extends AbstractBundle {
@NonNls
public static final String ONEDAY_BUNDLE = "CodeChronoBundle";
private static final CodeChronoBundle INSTANCE = new CodeChronoBundle();
private CodeChronoBundle() {
super(ONEDAY_BUNDLE);
}
//项目中可调用该静态方法,为组件文本赋值
@NotNull
public static String message(@NotNull @PropertyKey(resourceBundle = ONEDAY_BUNDLE) String key, @NotNull Object ... params) {
return INSTANCE.getMessage(key, params);
}
}
项目中使用
//组件文本赋值
weekRadioButton.setText(message("contentJpanel.weekRadioButton.text"));
推荐链接:
创建Java插件项目 | IntelliJ Platform Plugin SDK (beansoft.github.io)
IntelliJ Platform SDK | IntelliJ Platform Plugin SDK (jetbrains.com)