Skip to content

Commit 38ffdd6

Browse files
authored
Merge pull request #28 from Airsaid/feature_2.0.0
Feature 2.0.0
2 parents b7f68e9 + 12c6a22 commit 38ffdd6

File tree

77 files changed

+3941
-2145
lines changed

Some content is hidden

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

77 files changed

+3941
-2145
lines changed

.run/Run IDE with Plugin.run.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Run Plugin" type="GradleRunConfiguration" factoryName="Gradle">
3+
<log_file alias="idea.log" path="$PROJECT_DIR$/build/idea-sandbox/system/log/idea.log" />
4+
<ExternalSystemSettings>
5+
<option name="executionName" />
6+
<option name="externalProjectPath" value="$PROJECT_DIR$" />
7+
<option name="externalSystemIdString" value="GRADLE" />
8+
<option name="scriptParameters" value="" />
9+
<option name="taskDescriptions">
10+
<list />
11+
</option>
12+
<option name="taskNames">
13+
<list>
14+
<option value="runIde" />
15+
</list>
16+
</option>
17+
<option name="vmOptions" value="" />
18+
</ExternalSystemSettings>
19+
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
20+
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
21+
<DebugAllEnabled>false</DebugAllEnabled>
22+
<method v="2" />
23+
</configuration>
24+
</component>

.run/Run Plugin Tests.run.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Run Tests" type="GradleRunConfiguration" factoryName="Gradle">
3+
<log_file alias="idea.log" path="$PROJECT_DIR$/build/idea-sandbox/system/log/idea.log" />
4+
<ExternalSystemSettings>
5+
<option name="executionName" />
6+
<option name="externalProjectPath" value="$PROJECT_DIR$" />
7+
<option name="externalSystemIdString" value="GRADLE" />
8+
<option name="scriptParameters" value="" />
9+
<option name="taskDescriptions">
10+
<list />
11+
</option>
12+
<option name="taskNames">
13+
<list>
14+
<option value="check" />
15+
</list>
16+
</option>
17+
<option name="vmOptions" value="" />
18+
</ExternalSystemSettings>
19+
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
20+
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
21+
<DebugAllEnabled>false</DebugAllEnabled>
22+
<method v="2" />
23+
</configuration>
24+
</component>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Run Verifications" type="GradleRunConfiguration" factoryName="Gradle">
3+
<log_file alias="idea.log" path="$PROJECT_DIR$/build/idea-sandbox/system/log/idea.log" />
4+
<ExternalSystemSettings>
5+
<option name="executionName" />
6+
<option name="externalProjectPath" value="$PROJECT_DIR$" />
7+
<option name="externalSystemIdString" value="GRADLE" />
8+
<option name="scriptParameters" value="" />
9+
<option name="taskDescriptions">
10+
<list />
11+
</option>
12+
<option name="taskNames">
13+
<list>
14+
<option value="runPluginVerifier" />
15+
</list>
16+
</option>
17+
<option name="vmOptions" value="" />
18+
</ExternalSystemSettings>
19+
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
20+
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
21+
<DebugAllEnabled>false</DebugAllEnabled>
22+
<method v="2">
23+
<option name="Gradle.BeforeRunTask" enabled="true" tasks="clean" externalProjectPath="$PROJECT_DIR$" vmOptions="" scriptParameters="" />
24+
</method>
25+
</configuration>
26+
</component>

CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Change Log
2+
3+
## [V2.0.0](https://github.com/Airsaid/AndroidLocalizePlugin/releases/tag/v2.0.0) (2021-06-04)
4+
- Completely refactor the code.
5+
- Added multiple translator support.
6+
- Added "Open Translated File" option.
7+
- Added translation cache.
8+
- Optimized the experience.
9+
- Fixed bugs.
10+
11+
## [V1.5](https://github.com/Airsaid/AndroidLocalizePlugin/releases/tag/v1.5) (2020-03-28)
12+
- Added "Select All" option.
13+
14+
## [V1.4](https://github.com/Airsaid/AndroidLocalizePlugin/releases/tag/v1.4) (2020-03-28)
15+
- Added proxy support.
16+
- Fixed bugs.
17+
18+
## V1.3
19+
- Added "Overwrite Existing String" option.
20+
- Optimize the experience of choice.
21+
22+
## V1.2
23+
- Fixed garbled bug.
24+
25+
## V1.1
26+
- Supported for automatic detection of source file language.
27+
28+
## V1.0
29+
- Initial release of the plugin.

build.gradle

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

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

99
sourceCompatibility = 1.8
1010

@@ -13,22 +13,22 @@ repositories {
1313
}
1414

1515
dependencies {
16-
implementation 'org.apache.httpcomponents:httpclient:4.5.5'
17-
implementation 'org.apache.httpcomponents:httpcore:4.4.9'
18-
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.5'
19-
implementation 'com.fasterxml.jackson.core:jackson-core:2.9.5'
20-
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.5'
16+
implementation 'com.google.code.gson:gson:2.8.7'
2117

2218
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
2319
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
2420
}
2521

26-
// See https://github.com/JetBrains/gradle-intellij-plugin/
2722
intellij {
2823
version '2020.2.4'
24+
updateSinceUntilBuild false
2925
plugins = ['com.intellij.java']
3026
}
3127

3228
test {
3329
useJUnitPlatform()
30+
}
31+
32+
publishPlugin {
33+
token = System.getenv("INTELLIJ_PUBLISH_TOKEN")
3434
}

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

Lines changed: 0 additions & 135 deletions
This file was deleted.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright 2018 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+
package com.airsaid.localization.action;
18+
19+
import com.airsaid.localization.config.SettingsState;
20+
import com.airsaid.localization.model.AndroidString;
21+
import com.airsaid.localization.services.AndroidStringsService;
22+
import com.airsaid.localization.task.TranslateTask;
23+
import com.airsaid.localization.translate.lang.Lang;
24+
import com.airsaid.localization.ui.SelectLanguagesDialog;
25+
import com.airsaid.localization.utils.NotificationUtil;
26+
import com.intellij.openapi.actionSystem.AnAction;
27+
import com.intellij.openapi.actionSystem.AnActionEvent;
28+
import com.intellij.openapi.actionSystem.CommonDataKeys;
29+
import com.intellij.openapi.project.Project;
30+
import com.intellij.psi.PsiFile;
31+
import org.jetbrains.annotations.NotNull;
32+
33+
import java.util.List;
34+
35+
/**
36+
* Translate strings.xml to other languages that can be used to localize your Android APP.
37+
*
38+
* @author airsaid
39+
*/
40+
public class TranslateAction extends AnAction implements SelectLanguagesDialog.OnClickListener {
41+
42+
private Project mProject;
43+
private PsiFile mStringsFile;
44+
private List<AndroidString> mAndroidStrings;
45+
private final AndroidStringsService mStringsService = AndroidStringsService.getInstance();
46+
47+
@Override
48+
public void actionPerformed(AnActionEvent e) {
49+
mProject = e.getRequiredData(CommonDataKeys.PROJECT);
50+
mStringsFile = e.getRequiredData(CommonDataKeys.PSI_FILE);
51+
52+
SettingsState.getInstance().initSetting();
53+
54+
mStringsService.loadStringsByAsync(mStringsFile, androidStrings -> {
55+
if (!isTranslatable(androidStrings)) {
56+
NotificationUtil.notifyInfo(mProject, "The strings.xml has no text to translate.");
57+
return;
58+
}
59+
mAndroidStrings = androidStrings;
60+
showSelectLanguageDialog();
61+
});
62+
}
63+
64+
// Verify that there is a text in the strings.xml file that needs to be translated.
65+
private boolean isTranslatable(@NotNull List<AndroidString> androidStrings) {
66+
boolean isTranslatable = false;
67+
for (AndroidString androidString : androidStrings) {
68+
if (androidString.isTranslatable()) {
69+
isTranslatable = true;
70+
break;
71+
}
72+
}
73+
return isTranslatable;
74+
}
75+
76+
private void showSelectLanguageDialog() {
77+
SelectLanguagesDialog dialog = new SelectLanguagesDialog(mProject);
78+
dialog.setOnClickListener(this);
79+
dialog.show();
80+
}
81+
82+
@Override
83+
public void update(@NotNull AnActionEvent e) {
84+
// The translation option is only show when strings.xml is selected
85+
Project project = e.getData(CommonDataKeys.PROJECT);
86+
boolean isSelectStringsFile = mStringsService.isStringsFile(e.getData(CommonDataKeys.PSI_FILE));
87+
e.getPresentation().setEnabledAndVisible(project != null && isSelectStringsFile);
88+
}
89+
90+
@Override
91+
public void onClickListener(List<Lang> selectedLanguage) {
92+
TranslateTask translationTask = new TranslateTask(mProject, "Translating...", selectedLanguage, mAndroidStrings, mStringsFile);
93+
translationTask.setOnTranslateListener(new TranslateTask.OnTranslateListener() {
94+
@Override
95+
public void onTranslateSuccess() {
96+
NotificationUtil.notifyInfo(mProject, "Translation completed!");
97+
}
98+
99+
@Override
100+
public void onTranslateError(Throwable e) {
101+
NotificationUtil.notifyWarning(mProject, "Translation error: " + e);
102+
}
103+
});
104+
translationTask.queue();
105+
}
106+
107+
}

0 commit comments

Comments
 (0)