Skip to content

Commit 02906be

Browse files
committed
Feat: Support localization
1 parent e4c4b24 commit 02906be

File tree

11 files changed

+170
-79
lines changed

11 files changed

+170
-79
lines changed

src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvPlugin.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettingsProvider;
1717
import org.jetbrains.annotations.NotNull;
1818

19+
import java.util.ResourceBundle;
20+
1921
public class CsvPlugin implements StartupActivity, StartupActivity.DumbAware {
2022

23+
private static ResourceBundle _resourceBundle;
24+
2125
protected static IdeaPluginDescriptor getPluginDescriptor() {
2226
return PluginManagerCore.getPlugin(PluginId.getId("net.seesharpsoft.intellij.plugins.csv"));
2327
}
@@ -101,4 +105,15 @@ public void runActivity(@NotNull Project project) {
101105

102106
Notifications.Bus.notify(notification);
103107
}
108+
109+
public static ResourceBundle getResourceBundle() {
110+
if (_resourceBundle == null) {
111+
_resourceBundle = ResourceBundle.getBundle("i18n/CSVEditorResources");
112+
}
113+
return _resourceBundle;
114+
}
115+
116+
public static String getLocalizedText(String token) {
117+
return getResourceBundle().getString(token);
118+
}
104119
}

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorActionListeners.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package net.seesharpsoft.intellij.plugins.csv.editor.table.swing;
22

3-
import com.intellij.ide.BrowserUtil;
43
import com.intellij.openapi.fileEditor.FileEditorManager;
54
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
65
import com.intellij.ui.components.labels.LinkLabel;
@@ -25,7 +24,7 @@ public class CsvTableEditorActionListeners extends CsvTableEditorUtilBase implem
2524
protected ActionListener adjustColumnWidthAction = event -> adjustColumnWidths(csvTableEditor);
2625
protected ActionListener resetColumnWidthAction = event -> resetColumnWidths(csvTableEditor);
2726

28-
protected LinkListener openTextEditor = new OpenTextEditor();
27+
protected LinkListener<Object> openTextEditor = new OpenTextEditor();
2928

3029
public CsvTableEditorActionListeners(CsvTableEditorSwing tableEditor) {
3130
super(tableEditor);
@@ -89,7 +88,7 @@ public void deleteSelectedRows(CsvTableEditorSwing tableEditor) {
8988
}
9089
int currentColumn = table.getSelectedColumn();
9190

92-
tableEditor.removeRows(Arrays.stream(currentRows).map(row -> table.convertRowIndexToModel(row)).boxed().collect(Collectors.toList()));
91+
tableEditor.removeRows(Arrays.stream(currentRows).map(table::convertRowIndexToModel).boxed().collect(Collectors.toList()));
9392

9493
selectCell(table, currentRows[0], currentColumn);
9594
} finally {
@@ -116,7 +115,7 @@ public void deleteSelectedColumns(CsvTableEditorSwing tableEditor) {
116115
tableEditor.removeColumns(
117116
Arrays.stream(selectedColumns)
118117
.filter(selectedColumn -> selectedColumn >= 0 && selectedColumn < columnCount)
119-
.map(col -> table.convertColumnIndexToModel(col))
118+
.map(table::convertColumnIndexToModel)
120119
.boxed()
121120
.collect(Collectors.toList())
122121
);
@@ -148,8 +147,8 @@ public void clearSelectedCells(CsvTableEditorSwing tableEditor) {
148147
int focusedColumn = table.getSelectedColumn();
149148

150149
tableEditor.clearCells(
151-
Arrays.stream(selectedRows).map(row -> table.convertRowIndexToModel(row)).boxed().collect(Collectors.toList()),
152-
Arrays.stream(selectedColumns).map(col -> table.convertColumnIndexToModel(col)).boxed().collect(Collectors.toList())
150+
Arrays.stream(selectedRows).map(table::convertRowIndexToModel).boxed().collect(Collectors.toList()),
151+
Arrays.stream(selectedColumns).map(table::convertColumnIndexToModel).boxed().collect(Collectors.toList())
153152
);
154153

155154
selectCell(table, focusedRow, focusedColumn);
@@ -167,10 +166,15 @@ private void selectCell(JTable table, int row, int column) {
167166
table.changeSelection(actualRow, actualColumn, false, false);
168167
}
169168

170-
private final class OpenTextEditor implements LinkListener {
169+
private final class OpenTextEditor implements LinkListener<Object> {
171170
@Override
172171
public void linkSelected(LinkLabel linkLabel, Object o) {
173-
FileEditorManager.getInstance(csvTableEditor.getProject()).openTextEditor(new OpenFileDescriptor(csvTableEditor.getProject(), csvTableEditor.getFile()), true);
172+
if (csvTableEditor.getProject() != null && csvTableEditor.getFile() != null) {
173+
FileEditorManager.getInstance(csvTableEditor.getProject()).openTextEditor(
174+
new OpenFileDescriptor(csvTableEditor.getProject(), csvTableEditor.getFile()),
175+
true
176+
);
177+
}
174178
}
175179
}
176180
}

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorSwing.form

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</constraints>
2727
<properties>
2828
<horizontalTextPosition value="10"/>
29-
<text value="Open file in text editor"/>
29+
<text resource-bundle="i18n/CSVEditorResources" key="open.file.in.text.editor"/>
3030
</properties>
3131
</component>
3232
<component id="157b0" class="javax.swing.JLabel" binding="lblErrorText">
@@ -37,7 +37,7 @@
3737
<properties>
3838
<font size="12" style="1"/>
3939
<foreground color="-65536"/>
40-
<text value=" Error while parsing content - please fix issues in text editor!"/>
40+
<text resource-bundle="i18n/CSVEditorResources" key="error.while.parsing.content.please.fix.issues.in.text.editor"/>
4141
</properties>
4242
</component>
4343
<component id="d8426" class="javax.swing.JToolBar$Separator">

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorSwing.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class CsvTableEditorSwing extends CsvTableEditor {
2626

2727
private JTable tblEditor;
2828
private JPanel panelMain;
29-
private LinkLabel lnkTextEditor;
29+
private LinkLabel<Object> lnkTextEditor;
3030
private JLabel lblErrorText;
3131
private JScrollPane tableScrollPane;
3232
private JPanel panelTop;
@@ -61,10 +61,12 @@ public CsvTableEditorSwing(@NotNull Project projectArg, @NotNull VirtualFile fil
6161
protected void createUIComponents() {
6262
tblEditor = new CsvTable(new CsvTableModelSwing(this));
6363
tblEditor.setRowSorter(null);
64-
lnkTextEditor = new LinkLabel("Open file in text editor", null);
64+
lnkTextEditor = new LinkLabel<>("Open.file.in.text.editor", null);
6565
}
6666

6767
private void initializedUIComponents() {
68+
lnkTextEditor.setListener(this.tableEditorActions.openTextEditor, null);
69+
6870
EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
6971

7072
tblEditor.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvCodeStyleSettingsProvider.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,28 @@
88
import com.intellij.psi.PsiFile;
99
import com.intellij.psi.codeStyle.*;
1010
import net.seesharpsoft.intellij.plugins.csv.CsvLanguage;
11+
import net.seesharpsoft.intellij.plugins.csv.CsvPlugin;
1112
import org.jetbrains.annotations.NotNull;
1213
import org.jetbrains.annotations.Nullable;
1314

1415
public class CsvCodeStyleSettingsProvider extends CodeStyleSettingsProvider {
1516
@Override
16-
public CustomCodeStyleSettings createCustomSettings(CodeStyleSettings settings) {
17+
public CustomCodeStyleSettings createCustomSettings(@NotNull CodeStyleSettings settings) {
1718
return new CsvCodeStyleSettings(settings);
1819
}
1920

2021
@Nullable
2122
@Override
2223
public String getConfigurableDisplayName() {
23-
return "CSV/TSV/PSV";
24+
return CsvPlugin.getLocalizedText("settings.title");
2425
}
2526

2627
@NotNull
2728
@Override
28-
public CodeStyleConfigurable createConfigurable(CodeStyleSettings settings, CodeStyleSettings originalSettings) {
29+
public CodeStyleConfigurable createConfigurable(@NotNull CodeStyleSettings settings, @NotNull CodeStyleSettings originalSettings) {
2930
return new CodeStyleAbstractConfigurable(settings, originalSettings, CsvLanguage.INSTANCE.getDisplayName()) {
3031
@Override
31-
protected CodeStyleAbstractPanel createPanel(CodeStyleSettings settings) {
32+
protected @NotNull CodeStyleAbstractPanel createPanel(@NotNull CodeStyleSettings settings) {
3233
return new CsvCodeStyleMainPanel(getCurrentSettings(), settings);
3334
}
3435

@@ -64,8 +65,8 @@ public CsvWrappingPanel(CodeStyleSettings settings) {
6465
}
6566

6667
@Override
67-
public String getTabTitle() {
68-
return "Wrapping";
68+
public @NotNull String getTabTitle() {
69+
return CsvPlugin.getLocalizedText("settings.codestyle.wrapping");
6970
}
7071
}
7172

@@ -75,8 +76,8 @@ public CsvSpacesPanel(CodeStyleSettings settings) {
7576
}
7677

7778
@Override
78-
protected String getTabTitle() {
79-
return "Spaces";
79+
protected @NotNull String getTabTitle() {
80+
return CsvPlugin.getLocalizedText("settings.codestyle.spaces");
8081
}
8182

8283
@Override
@@ -85,7 +86,7 @@ public LanguageCodeStyleSettingsProvider.SettingsType getSettingsType() {
8586
}
8687

8788
@Override
88-
protected PsiFile doReformat(Project project, PsiFile psiFile) {
89+
protected @NotNull PsiFile doReformat(Project project, @NotNull PsiFile psiFile) {
8990
CodeStyleManager.getInstance(project).reformatText(psiFile, 0, psiFile.getTextLength());
9091
return psiFile;
9192
}

src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvColorSettings.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.intellij.openapi.util.UserDataHolder;
1515
import net.seesharpsoft.UnhandledSwitchCaseException;
1616
import net.seesharpsoft.intellij.plugins.csv.CsvIconProvider;
17+
import net.seesharpsoft.intellij.plugins.csv.CsvPlugin;
1718
import net.seesharpsoft.intellij.plugins.csv.highlighter.CsvSyntaxHighlighter;
1819
import org.jetbrains.annotations.NotNull;
1920
import org.jetbrains.annotations.Nullable;
@@ -22,6 +23,7 @@
2223
import java.util.ArrayList;
2324
import java.util.List;
2425
import java.util.Map;
26+
import java.util.ResourceBundle;
2527

2628
import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey;
2729

@@ -46,20 +48,21 @@ public class CsvColorSettings implements ColorSettingsPage {
4648
private static final Key<List<TextAttributes>> COLUMN_COLORING_TEXT_ATTRIBUTES = Key.create("CSV_PLUGIN_COLUMN_COLORING_ATTRIBUTES");
4749

4850
static {
49-
List<AttributesDescriptor> attributesDescriptors = new ArrayList();
50-
attributesDescriptors.add(new AttributesDescriptor("Separator", COMMA));
51-
attributesDescriptors.add(new AttributesDescriptor("Quote", QUOTE));
52-
attributesDescriptors.add(new AttributesDescriptor("Text", TEXT));
53-
attributesDescriptors.add(new AttributesDescriptor("Escaped Text", ESCAPED_TEXT));
54-
attributesDescriptors.add(new AttributesDescriptor("Comment", COMMENT));
51+
List<AttributesDescriptor> attributesDescriptors = new ArrayList<>();
52+
ResourceBundle bundle = CsvPlugin.getResourceBundle();
53+
attributesDescriptors.add(new AttributesDescriptor(bundle.getString("color.attribute.separator"), COMMA));
54+
attributesDescriptors.add(new AttributesDescriptor(bundle.getString("color.attribute.quote"), QUOTE));
55+
attributesDescriptors.add(new AttributesDescriptor(bundle.getString("color.attribute.text"), TEXT));
56+
attributesDescriptors.add(new AttributesDescriptor(bundle.getString("color.attribute.text.escaped"), ESCAPED_TEXT));
57+
attributesDescriptors.add(new AttributesDescriptor(bundle.getString("color.attribute.comment"), COMMENT));
5558

5659
COLUMN_COLORING_ATTRIBUTES = new ArrayList<>();
5760
for (int i = 0; i < MAX_COLUMN_COLORING_COLORS; ++i) {
5861
TextAttributesKey textAttributesKey = createTextAttributesKey(String.format("CSV_PLUGIN_COLUMN_COLORING_ATTRIBUTE_%d", i), TEXT);
5962
COLUMN_COLORING_ATTRIBUTES.add(textAttributesKey);
60-
attributesDescriptors.add(new AttributesDescriptor(String.format("Column Color %d", i + 1), textAttributesKey));
63+
attributesDescriptors.add(new AttributesDescriptor(String.format(bundle.getString("color.attribute.column.nr"), i + 1), textAttributesKey));
6164
}
62-
DESCRIPTORS = attributesDescriptors.toArray(new AttributesDescriptor[attributesDescriptors.size()]);
65+
DESCRIPTORS = attributesDescriptors.toArray(new AttributesDescriptor[0]);
6366
}
6467

6568
public static TextAttributesKey getTextAttributesKeys(int columnIndex) {
@@ -150,6 +153,6 @@ public ColorDescriptor[] getColorDescriptors() {
150153
@NotNull
151154
@Override
152155
public String getDisplayName() {
153-
return "CSV/TSV/PSV";
156+
return CsvPlugin.getLocalizedText("settings.title");
154157
}
155158
}

src/main/java/net/seesharpsoft/intellij/plugins/csv/settings/CsvEditorSettings.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import com.intellij.openapi.components.Storage;
88
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
99
import com.intellij.util.xmlb.annotations.OptionTag;
10+
import com.intellij.util.xmlb.annotations.Transient;
1011
import net.seesharpsoft.intellij.plugins.csv.CsvEscapeCharacter;
12+
import net.seesharpsoft.intellij.plugins.csv.CsvPlugin;
1113
import net.seesharpsoft.intellij.plugins.csv.CsvStorageHelper;
1214
import net.seesharpsoft.intellij.plugins.csv.CsvValueSeparator;
1315
import org.jetbrains.annotations.NotNull;
@@ -39,9 +41,9 @@ public class CsvEditorSettings implements PersistentStateComponent<CsvEditorSett
3941
private static final CsvEditorSettings STATIC_TEST_INSTANCE = new CsvEditorSettings();
4042

4143
public enum EditorPrio {
42-
TEXT_FIRST("Text editor first"),
43-
TABLE_FIRST("Table editor first"),
44-
TEXT_ONLY("Text editor only");
44+
TEXT_FIRST(CsvPlugin.getLocalizedText("settings.editor.prio.text_first")),
45+
TABLE_FIRST(CsvPlugin.getLocalizedText("settings.editor.prio.table_first")),
46+
TEXT_ONLY(CsvPlugin.getLocalizedText("settings.editor.prio.text_only"));
4547

4648
private final String label;
4749

@@ -55,8 +57,8 @@ public String getDisplay() {
5557
}
5658

5759
public enum ValueColoring {
58-
RAINBOW("Rainbow (Column Color)"),
59-
SIMPLE("Simple (Text Color)");
60+
RAINBOW(CsvPlugin.getLocalizedText("settings.editor.coloring.rainbow")),
61+
SIMPLE(CsvPlugin.getLocalizedText("settings.editor.coloring.simple"));
6062

6163
private final String display;
6264

@@ -93,7 +95,7 @@ public static final class OptionSet {
9395
public String COMMENT_INDICATOR = COMMENT_INDICATOR_DEFAULT;
9496
public ValueColoring VALUE_COLORING = ValueColoring.RAINBOW;
9597
public boolean AUTO_DETECT_VALUE_SEPARATOR = true;
96-
98+
@Transient
9799
private boolean isInitialized = false;
98100

99101
public OptionSet() {}

0 commit comments

Comments
 (0)