2.08 i18n and chinese | 多语言与中文支持

This commit is contained in:
林万程
2023-01-08 21:10:50 +08:00
parent 2c1c6cc5ac
commit 669e818f16
17 changed files with 244 additions and 65 deletions

View File

@@ -8,6 +8,7 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import io.github.linwancen.plugin.show.settings.ShowBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -19,10 +20,7 @@ public class CopyReferenceSimple extends CopyReferenceAction {
@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);
String tip = IdeBundle.message("copy.reference");
if (tip != null && tip.replace("\u001B", "").equals(e.getPresentation().getText())) {
e.getPresentation().setText("Copy Class.Method / File:Line");
}
e.getPresentation().setText(ShowBundle.message("copy.class.method.or.file.line"));
}
private static final Pattern QUALIFIED_PATTERN = Pattern.compile("[\\w.]+\\.");

View File

@@ -12,6 +12,7 @@ import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileVisitor;
import io.github.linwancen.plugin.show.bean.FileInfo;
import io.github.linwancen.plugin.show.settings.ShowBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -20,6 +21,12 @@ import org.jetbrains.annotations.Nullable;
*/
public class LineEndAdd extends DumbAwareAction {
@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);
e.getPresentation().setText(ShowBundle.message("line.end.add"));
}
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
@Nullable Project project = event.getProject();

View File

@@ -8,6 +8,7 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.ide.CopyPasteManager;
import com.intellij.openapi.project.DumbAwareAction;
import io.github.linwancen.plugin.show.bean.FileInfo;
import io.github.linwancen.plugin.show.settings.ShowBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -18,6 +19,12 @@ import java.awt.datatransfer.StringSelection;
*/
public class LineEndCopy extends DumbAwareAction {
@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);
e.getPresentation().setText(ShowBundle.message("line.end.copy"));
}
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
ApplicationManager.getApplication().runReadAction(() -> copyWithDoc(event));

View File

@@ -97,13 +97,15 @@ public class ConfCacheGetUtils {
String[] paths = StringUtils.split(path, '/');
String[] confPaths = StringUtils.split(confPath, '/');
int length = confPaths.length;
String lastFolder = confPaths[length - 2];
if (lastFolder.startsWith("-")) {
try {
int i = Integer.parseInt(lastFolder);
length = length + i - 1;
} catch (NumberFormatException e) {
// ignore
if (length > 1) {
String lastFolder = confPaths[length - 2];
if (lastFolder.startsWith("-")) {
try {
int i = Integer.parseInt(lastFolder);
length = length + i - 1;
} catch (NumberFormatException e) {
// ignore
}
}
}
if (length > paths.length) {

View File

@@ -5,6 +5,7 @@ import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import io.github.linwancen.plugin.show.settings.ShowBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -12,6 +13,13 @@ import org.jetbrains.annotations.Nullable;
* call ConfCache.loadAll
*/
public class ReloadExtDocAction extends AnAction {
@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);
e.getPresentation().setText(ShowBundle.message("reload.ext.doc"));
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
@Nullable Project project = e.getProject();

View File

@@ -5,6 +5,7 @@ import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import io.github.linwancen.plugin.show.settings.ShowBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -13,6 +14,13 @@ import org.jetbrains.annotations.Nullable;
* <br>Use Reset only for file sort
*/
public class ResetExtDocAction extends AnAction {
@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);
e.getPresentation().setText(ShowBundle.message("reset.ext.doc"));
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
ConfCache.clearAll();

View File

@@ -23,18 +23,17 @@ public abstract class AbstractSettingsComponent {
@NotNull
protected JPanel commonLineEndFilter(FormBuilder formBuilder) {
formBuilder = formBuilder
.addComponent(new JBLabel("Separated by '|' (Regexp), use '' to include all or exclude none."))
.addComponent(new JBLabel(ShowBundle.message("regexp.tip")))
.addSeparator()
.addLabeledComponent(new JBLabel("className#memberName include Regexp: "), lineInclude, 1, true)
.addLabeledComponent(new JBLabel("className#memberName exclude Regexp: "), lineExclude, 1, true)
.addLabeledComponent(new JBLabel(ShowBundle.message("sign.include.regexp")), lineInclude, 1, true)
.addLabeledComponent(new JBLabel(ShowBundle.message("sign.exclude.regexp")), lineExclude, 1, true)
.addSeparator()
.addLabeledComponent(new JBLabel("comment include Regexp: "), docInclude, 1, true)
.addLabeledComponent(new JBLabel("comment exclude Regexp: "), docExclude, 1, true)
.addLabeledComponent(new JBLabel(ShowBundle.message("comment.include.regexp")), docInclude, 1, true)
.addLabeledComponent(new JBLabel(ShowBundle.message("comment.exclude.regexp")), docExclude, 1, true)
.addSeparator();
formBuilder = add(formBuilder, docGetEffect, this.docGet,
"get doc Regexp, last () when had, default is first sentence .+?(?:[。\\r\\n]|\\. ) :");
formBuilder = add(formBuilder, docGetEffect, this.docGet, ShowBundle.message("get.doc.regexp"));
JPanel lineEndFilter = formBuilder.getPanel();
lineEndFilter.setBorder(IdeBorderFactory.createTitledBorder("Line End Comment"));
lineEndFilter.setBorder(IdeBorderFactory.createTitledBorder(ShowBundle.message("line.end.comment")));
return lineEndFilter;
}

View File

@@ -15,11 +15,10 @@ import java.awt.*;
public class AppSettingsComponent extends AbstractSettingsComponent {
private final JPanel myMainPanel;
private final JButton resetDefault = new JButton("Reset default ");
private final JBCheckBox showTreeComment = new JBCheckBox("Show tree comment ");
private final JBCheckBox compact = new JBCheckBox("compact ");
private final JBCheckBox showTreeComment = new JBCheckBox(ShowBundle.message("show.tree.comment"));
private final JBCheckBox compact = new JBCheckBox(ShowBundle.message("compact"));
private final JBTextField treeTags = new JBTextField();
private final JBCheckBox showLineEndComment = new JBCheckBox("Show line end comment ");
private final JBCheckBox showLineEndComment = new JBCheckBox(ShowBundle.message("show.line.end.comment"));
private final JBCheckBox showLineEndCommentJava = new JBCheckBox("Java ");
private final JBCheckBox showLineEndCommentSql = new JBCheckBox("sql ");
private final JBCheckBox showLineEndCommentJson = new JBCheckBox("json ");
@@ -29,25 +28,26 @@ public class AppSettingsComponent extends AbstractSettingsComponent {
private final JBCheckBox showLineEndCommentGo = new JBCheckBox("Go ");
private final JBCheckBox showLineEndCommentKotlin = new JBCheckBox("Kotlin ");
private final JBTextField lineTags = new JBTextField();
private final JBCheckBox getToSet = new JBCheckBox("get |> set ");
private final JBCheckBox getToSet = new JBCheckBox("get --> set ");
private final JBCheckBox fromNew = new JBCheckBox("java new ");
private final JBCheckBox fromParam = new JBCheckBox("java param ");
private final JBCheckBox skipAnnotation = new JBCheckBox("skip @ ");
private final JBCheckBox skipAscii = new JBCheckBox("skip English ");
private final JBCheckBox skipBlank = new JBCheckBox("skip Blank ");
private final JBCheckBox fromParam = new JBCheckBox("java @param ");
private final JBCheckBox skipAnnotation = new JBCheckBox(ShowBundle.message("skip.anno"));
private final JBCheckBox skipAscii = new JBCheckBox(ShowBundle.message("skip.english"));
private final JBCheckBox skipBlank = new JBCheckBox(ShowBundle.message("skip.blank"));
private final ColorPanel lineEndColor = new ColorPanel();
private final ColorPanel lineEndJsonColor = new ColorPanel();
private final JBTextField lineEndPrefix = new JBTextField();
private final JBTextField lineEndCount = new JBTextField();
public AppSettingsComponent() {
JButton resetDefault = new JButton(ShowBundle.message("reset.default"));
resetDefault.addActionListener(e -> AppSettingsConfigurable.reset(AppSettingsState.DEFAULT_SETTING, this));
myMainPanel = FormBuilder.createFormBuilder()
.addComponent(resetDefault, 1)
.addComponent(showPanel(), 1)
.addComponent(lineEndFilterPanel(), 1)
.addComponentFillVertically(new JPanel(), 0)
.getPanel();
resetDefault.addActionListener(e -> AppSettingsConfigurable.reset(AppSettingsState.DEFAULT_SETTING, this));
}
@NotNull
@@ -64,20 +64,20 @@ public class AppSettingsComponent extends AbstractSettingsComponent {
showLineEndCommentGo,
showLineEndCommentKotlin
), 1)
.addLabeledComponent(new JBLabel("tree tags split by |:"), treeTags, 1, true)
.addLabeledComponent(new JBLabel("line tags split by |:"), lineTags, 1, true)
.addLabeledComponent(new JBLabel(ShowBundle.message("tree.tags")), treeTags, 1, true)
.addLabeledComponent(new JBLabel(ShowBundle.message("line.tags")), lineTags, 1, true)
.getPanel();
comment.setBorder(IdeBorderFactory.createTitledBorder("Show"));
comment.setBorder(IdeBorderFactory.createTitledBorder(ShowBundle.message("show")));
return comment;
}
@NotNull
protected JPanel lineEndFilterPanel() {
@NotNull JPanel text = JPanelFactory.of(
new JBLabel("line count: "), lineEndCount,
new JBLabel("text color: "), lineEndColor,
new JBLabel("json text color: "), lineEndJsonColor,
new JBLabel("prefix: "), lineEndPrefix);
new JBLabel(ShowBundle.message("line.count")), lineEndCount,
new JBLabel(ShowBundle.message("text.color")), lineEndColor,
new JBLabel(ShowBundle.message("text.color.json")), lineEndJsonColor,
new JBLabel(ShowBundle.message("prefix")), lineEndPrefix);
FormBuilder formBuilder = FormBuilder.createFormBuilder()
.addSeparator()
.addComponent(JPanelFactory.of(fromNew, fromParam, getToSet, skipAnnotation, skipAscii, skipBlank), 1)

View File

@@ -16,7 +16,7 @@ public class AppSettingsConfigurable implements Configurable {
@NotNull
@Override
public String getDisplayName() {
return "Show Comment Global.";
return "// Show Comment Global";
}
@NotNull

View File

@@ -9,8 +9,8 @@ import javax.swing.*;
public class ProjectSettingsComponent extends AbstractSettingsComponent {
private final JPanel myMainPanel;
private final JBCheckBox globalFilterEffective = new JBCheckBox("Global Include Exclude Effective");
private final JBCheckBox projectFilterEffective = new JBCheckBox("Project Include Exclude Effective");
private final JBCheckBox globalFilterEffective = new JBCheckBox(ShowBundle.message("global.include.exclude.effective"));
private final JBCheckBox projectFilterEffective = new JBCheckBox(ShowBundle.message("project.include.exclude.effective"));
public ProjectSettingsComponent() {
myMainPanel = FormBuilder.createFormBuilder()

View File

@@ -27,7 +27,7 @@ public class ProjectSettingsConfigurable extends ModuleAwareProjectConfigurable<
@NotNull
@Override
public String getDisplayName() {
return "Show Comment Project.";
return "// Show Comment Project";
}
@NotNull

View File

@@ -0,0 +1,30 @@
package io.github.linwancen.plugin.show.settings;
import com.intellij.DynamicBundle;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.PropertyKey;
import java.util.function.Supplier;
public class ShowBundle extends DynamicBundle {
@NonNls
public static final String BUNDLE = "messages.ShowCommentBundle";
private static final ShowBundle INSTANCE = new ShowBundle();
private ShowBundle() {
super(BUNDLE);
}
@NotNull
public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key,
@NotNull Object... params) {
return INSTANCE.getMessage(key, params);
}
@NotNull
public static Supplier<String> messagePointer(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key,
@NotNull Object... params) {
return INSTANCE.getLazyMessage(key, params);
}
}