Skip to content

Commit 5262d9c

Browse files
authored
Merge pull request #29 from Airsaid/v2.1.0
V2.1.0
2 parents 31ad1be + 12bf41d commit 5262d9c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1072
-83
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## [V2.1.0](https://github.com/Airsaid/AndroidLocalizePlugin/releases/tag/v2.1.0) (2021-06-05)
4+
- Added Microsoft Translator.
5+
- Added "Use google.com" setting.
6+
- Supported more languages.
7+
38
## [V2.0.0](https://github.com/Airsaid/AndroidLocalizePlugin/releases/tag/v2.0.0) (2021-06-04)
49
- Completely refactor the code.
510
- Added multiple translator support.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Features
88
- Multiple translator support:
99
- Google translator.
10+
- Microsoft translator.
1011
- Baidu translator.
1112
- Youdao translator.
1213
- Supports up to 100+ languages.

README_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# 功能
88
- 多翻译器支持:
99
- Google 翻译
10+
- 微软翻译
1011
- 百度翻译
1112
- 有道翻译
1213
- 支持最多 100+ 语言。

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group 'com.airsaid'
7-
version '2.0.0'
7+
version '2.1.0'
88

99
sourceCompatibility = 1.8
1010

src/main/java/com/airsaid/localization/action/TranslateAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 Airsaid. https://github.com/airsaid
2+
* Copyright 2021 Airsaid. https://github.com/airsaid
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -12,6 +12,7 @@
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15+
*
1516
*/
1617

1718
package com.airsaid.localization.action;

src/main/java/com/airsaid/localization/config/SettingsComponent.form

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
<grid id="27dc6" binding="contentJPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>
6-
<xy x="20" y="20" width="500" height="400"/>
6+
<xy x="20" y="20" width="558" height="400"/>
77
</constraints>
88
<properties/>
99
<border type="none"/>
1010
<children>
11-
<grid id="c2e63" layout-manager="GridLayoutManager" row-count="3" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
11+
<grid id="c2e63" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
1212
<margin top="0" left="0" bottom="0" right="0"/>
1313
<constraints>
1414
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -67,14 +67,6 @@
6767
</constraints>
6868
<properties/>
6969
</component>
70-
<component id="4ef73" class="com.airsaid.localization.ui.FixedLinkLabel" binding="applyLink">
71-
<constraints>
72-
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
73-
</constraints>
74-
<properties>
75-
<text value="Apply..."/>
76-
</properties>
77-
</component>
7870
<component id="63820" class="javax.swing.JButton" binding="supportLanguagesButton" default-binding="true">
7971
<constraints>
8072
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
@@ -85,9 +77,25 @@
8577
</component>
8678
<hspacer id="b8e2f">
8779
<constraints>
88-
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
80+
<grid row="0" column="4" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
8981
</constraints>
9082
</hspacer>
83+
<component id="4ef73" class="com.airsaid.localization.ui.FixedLinkLabel" binding="applyLink">
84+
<constraints>
85+
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
86+
</constraints>
87+
<properties>
88+
<text value="Apply..."/>
89+
</properties>
90+
</component>
91+
<component id="2c115" class="javax.swing.JCheckBox" binding="useGoogleComCheckBox" default-binding="true">
92+
<constraints>
93+
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
94+
</constraints>
95+
<properties>
96+
<text value="Use google.com"/>
97+
</properties>
98+
</component>
9199
</children>
92100
</grid>
93101
<grid id="b866e" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">

src/main/java/com/airsaid/localization/config/SettingsComponent.java

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
1+
/*
2+
* Copyright 2021 Airsaid. https://github.com/airsaid
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
118
package com.airsaid.localization.config;
219

320
import com.airsaid.localization.translate.AbstractTranslator;
21+
import com.airsaid.localization.translate.impl.google.GoogleTranslator;
422
import com.airsaid.localization.translate.services.TranslatorService;
523
import com.airsaid.localization.ui.FixedLinkLabel;
624
import com.airsaid.localization.ui.SupportLanguagesDialog;
@@ -40,6 +58,7 @@ public class SettingsComponent {
4058
private JLabel maxCacheSizeLabel;
4159
private JBCheckBox enableCacheCheckBox;
4260
private ComboBox<String> maxCacheSizeComboBox;
61+
private JCheckBox useGoogleComCheckBox;
4362

4463
public SettingsComponent() {
4564
initTranslatorComponents();
@@ -107,19 +126,19 @@ public void setTranslators(@NotNull Map<String, AbstractTranslator> translators)
107126
public void setSelectedTranslator(@NotNull AbstractTranslator selected) {
108127
LOG.info("setSelectedTranslator: " + selected);
109128
translatorsComboBox.setSelectedItem(selected);
110-
if (isSelectedDefaultTranslator(selected)) {
111-
appIdLabel.setVisible(false);
112-
appKeyLabel.setVisible(false);
113-
appIdField.setVisible(false);
114-
appKeyField.setVisible(false);
115-
} else {
116-
appIdLabel.setVisible(true);
117-
appKeyLabel.setVisible(true);
118-
appIdField.setVisible(true);
119-
appKeyField.setVisible(true);
120-
appIdField.setText(selected.getAppId());
121-
appKeyField.setText(selected.getAppKey());
122-
}
129+
130+
useGoogleComCheckBox.setVisible(selected.getClass() == GoogleTranslator.class);
131+
132+
boolean isNeedAppId = selected.isNeedAppId();
133+
appIdLabel.setVisible(isNeedAppId);
134+
appIdField.setVisible(isNeedAppId);
135+
if (isNeedAppId) appIdField.setText(selected.getAppId());
136+
137+
boolean isNeedAppKey = selected.isNeedAppKey();
138+
appKeyLabel.setVisible(isNeedAppKey);
139+
appKeyField.setVisible(isNeedAppKey);
140+
if (isNeedAppKey) appKeyField.setText(selected.getAppKey());
141+
123142
String applyAppIdUrl = selected.getApplyAppIdUrl();
124143
if (!StringUtil.isEmpty(applyAppIdUrl)) {
125144
applyLink.setVisible(true);
@@ -139,6 +158,14 @@ private boolean isSelectedDefaultTranslator(@NotNull AbstractTranslator selected
139158
return selected == TranslatorService.getInstance().getDefaultTranslator();
140159
}
141160

161+
public boolean isUseGoogleCom() {
162+
return useGoogleComCheckBox.isSelected();
163+
}
164+
165+
public void setUseGoogleCom(boolean useGoogleCom) {
166+
useGoogleComCheckBox.setSelected(useGoogleCom);
167+
}
168+
142169
@NotNull
143170
public String getAppId() {
144171
String appId = appIdField.getText();

src/main/java/com/airsaid/localization/config/SettingsConfigurable.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1+
/*
2+
* Copyright 2021 Airsaid. https://github.com/airsaid
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
118
package com.airsaid.localization.config;
219

320
import com.airsaid.localization.constant.Constants;
421
import com.airsaid.localization.translate.AbstractTranslator;
22+
import com.airsaid.localization.translate.impl.google.GoogleTranslator;
523
import com.airsaid.localization.translate.services.TranslatorService;
624
import com.intellij.openapi.diagnostic.Logger;
725
import com.intellij.openapi.options.Configurable;
@@ -40,6 +58,7 @@ private void initComponents() {
4058
SettingsState settingsState = SettingsState.getInstance();
4159
Map<String, AbstractTranslator> translators = TranslatorService.getInstance().getTranslators();
4260
settingsComponent.setTranslators(translators);
61+
settingsComponent.setUseGoogleCom(settingsState.isUseGoogleCom());
4362
settingsComponent.setSelectedTranslator(translators.get(settingsState.getSelectedTranslator().getKey()));
4463
settingsComponent.setEnableCache(settingsState.isEnableCache());
4564
settingsComponent.setMaxCacheSize(settingsState.getMaxCacheSize());
@@ -50,6 +69,7 @@ public boolean isModified() {
5069
SettingsState settingsState = SettingsState.getInstance();
5170
AbstractTranslator selectedTranslator = settingsComponent.getSelectedTranslator();
5271
boolean isChanged = settingsState.getSelectedTranslator() == selectedTranslator;
72+
isChanged |= settingsState.isUseGoogleCom() == settingsComponent.isUseGoogleCom();
5373
isChanged |= settingsState.getAppId(selectedTranslator.getKey()).equals(selectedTranslator.getAppId());
5474
isChanged |= settingsState.getAppKey(selectedTranslator.getKey()).equals(selectedTranslator.getAppKey());
5575
isChanged |= settingsState.isEnableCache() == settingsComponent.isEnableCache();
@@ -64,15 +84,21 @@ public void apply() {
6484
AbstractTranslator selectedTranslator = settingsComponent.getSelectedTranslator();
6585
LOG.info("apply selectedTranslator: " + selectedTranslator.getName());
6686
settingsState.setSelectedTranslator(selectedTranslator);
67-
if (!settingsComponent.isSelectedDefaultTranslator()) {
87+
if (selectedTranslator.getClass() == GoogleTranslator.class) {
88+
settingsState.setUseGoogleCom(settingsComponent.isUseGoogleCom());
89+
}
90+
if (selectedTranslator.isNeedAppId()) {
6891
settingsState.setAppId(selectedTranslator.getKey(), settingsComponent.getAppId());
92+
}
93+
if (selectedTranslator.isNeedAppKey()) {
6994
settingsState.setAppKey(selectedTranslator.getKey(), settingsComponent.getAppKey());
7095
}
7196
settingsState.setEnableCache(settingsComponent.isEnableCache());
7297
settingsState.setMaxCacheSize(settingsComponent.getMaxCacheSize());
7398

7499
TranslatorService translatorService = TranslatorService.getInstance();
75100
translatorService.setSelectedTranslator(selectedTranslator);
101+
translatorService.setUseGoogleComHost(settingsComponent.isUseGoogleCom());
76102
translatorService.setEnableCache(settingsComponent.isEnableCache());
77103
translatorService.setMaxCacheSize(settingsComponent.getMaxCacheSize());
78104
}
@@ -83,6 +109,7 @@ public void reset() {
83109
SettingsState settingsState = SettingsState.getInstance();
84110
AbstractTranslator selectedTranslator = settingsState.getSelectedTranslator();
85111
settingsComponent.setSelectedTranslator(selectedTranslator);
112+
settingsComponent.setUseGoogleCom(settingsState.isUseGoogleCom());
86113
settingsComponent.setAppId(settingsState.getAppId(selectedTranslator.getKey()));
87114
settingsComponent.setAppKey(settingsState.getAppKey(selectedTranslator.getKey()));
88115
settingsComponent.setEnableCache(settingsState.isEnableCache());

src/main/java/com/airsaid/localization/config/SettingsState.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* Copyright 2021 Airsaid. https://github.com/airsaid
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
118
package com.airsaid.localization.config;
219

320
import com.airsaid.localization.translate.AbstractTranslator;
@@ -46,6 +63,7 @@ public static SettingsState getInstance() {
4663

4764
public void initSetting() {
4865
TranslatorService translatorService = TranslatorService.getInstance();
66+
translatorService.setUseGoogleComHost(isUseGoogleCom());
4967
AbstractTranslator selectedTranslator = translatorService.getSelectedTranslator();
5068
if (selectedTranslator == null) {
5169
LOG.info("initSetting");
@@ -64,6 +82,14 @@ public void setSelectedTranslator(AbstractTranslator translator) {
6482
this.state.selectedTranslatorKey = translator.getKey();
6583
}
6684

85+
public boolean isUseGoogleCom() {
86+
return state.isUseGoogleCom;
87+
}
88+
89+
public void setUseGoogleCom(boolean useGoogleCom) {
90+
state.isUseGoogleCom = useGoogleCom;
91+
}
92+
6793
public void setAppId(@NotNull String translatorKey, @NotNull String appId) {
6894
state.appIds.put(translatorKey, appId);
6995
}
@@ -118,5 +144,6 @@ static class State {
118144
public Map<String, String> appIds = new HashMap<>();
119145
public boolean isEnableCache = true;
120146
public int maxCacheSize = 100;
147+
public boolean isUseGoogleCom;
121148
}
122149
}

src/main/java/com/airsaid/localization/constant/Constants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 Airsaid. https://github.com/airsaid
2+
* Copyright 2021 Airsaid. https://github.com/airsaid
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -12,6 +12,7 @@
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15+
*
1516
*/
1617

1718
package com.airsaid.localization.constant;

0 commit comments

Comments
 (0)