Skip to content

Commit 68248c2

Browse files
frogggiasAirsaid
andauthored
Relax translation file name boundaries (#76)
* Relax translation file name boundaries * Update README_CN.md * Update CHANGELOG.md Co-authored-by: Airsaid <airsaid1024@gmail.com>
1 parent b8dc4a6 commit 68248c2

File tree

5 files changed

+8
-10
lines changed

5 files changed

+8
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
## [Unreleased]
66
### Changed
77
- Improve plugin description information.
8+
- Relax translation file name boundaries.
89

910
## [2.6.1](https://github.com/Airsaid/AndroidLocalizePlugin/releases/tag/v2.6.1) (2022-08-27)
1011
### Added

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Android localization plugin. supports multiple languages and multiple translator
2525
- Support to set the translation interval time.
2626

2727
# Usage
28-
- Step 1: Select the `values/strings.xml`(or `plurals.xml/arrays.xml`).
28+
- Step 1: Select the `values/strings.xml`(or any string resource in `values` directory).
2929
- Step 2: Right click and select "Translate to Other Languages".
3030
- Step 3: Select the languages to be translated.
3131
- Step 4: Click OK.

README_CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Android 本地化插件,支持多种语言和翻译器。
2424
- 支持设置翻译间隔时间。
2525

2626
# 使用
27-
- 第一步:选择 `values/strings.xml` 文件(或者 `plurals.xml/arrays.xml`)。
27+
- 第一步:选择 `values/strings.xml` 文件(或者是 values 目录下的任何资源文件)。
2828
- 第二步:右键选择:“Translate to Other Languages”。
2929
- 第三步:勾选上需要翻译的语言。
3030
- 第四步:点击 OK。

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private void showSelectLanguageDialog() {
8383

8484
@Override
8585
public void update(@NotNull AnActionEvent e) {
86-
// The translation option is only show when strings.xml/plurals.xml/arrays.xml is selected
86+
// The translation option is only show when xml file from values is selected
8787
Project project = e.getData(CommonDataKeys.PROJECT);
8888
boolean isSelectValueFile = mValueService.isValueFile(e.getData(CommonDataKeys.PSI_FILE));
8989
e.getPresentation().setEnabledAndVisible(project != null && isSelectValueFile);

src/main/java/com/airsaid/localization/services/AndroidValuesService.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@
4343
import java.util.ArrayList;
4444
import java.util.Arrays;
4545
import java.util.List;
46+
import java.util.regex.Pattern;
4647

4748
/**
48-
* Operation service for the android value files. eg: strings.xml or plurals.xml or arrays.xml.
49+
* Operation service for the android value files. eg: strings.xml (or any string resource from values directory).
4950
*
5051
* @author airsaid
5152
*/
@@ -54,9 +55,7 @@ public final class AndroidValuesService {
5455

5556
private static final Logger LOG = Logger.getInstance(AndroidValuesService.class);
5657

57-
private static final String NAME_STRINGS_FILE = "strings.xml";
58-
private static final String NAME_PLURALS_FILE = "plurals.xml";
59-
private static final String NAME_ARRAYS_FILE = "arrays.xml";
58+
private static final Pattern STRINGS_FILE_NAME_PATTERN = Pattern.compile(".+\\.xml");
6059

6160
/**
6261
* Returns the {@link AndroidValuesService} object instance.
@@ -154,9 +153,7 @@ public boolean isValueFile(@Nullable PsiFile file) {
154153
if (!"values".equals(parentName)) return false;
155154

156155
String fileName = file.getName();
157-
return NAME_STRINGS_FILE.equals(fileName) ||
158-
NAME_PLURALS_FILE.equals(fileName) ||
159-
NAME_ARRAYS_FILE.equals(fileName);
156+
return STRINGS_FILE_NAME_PATTERN.matcher(fileName).matches();
160157
}
161158

162159
/**

0 commit comments

Comments
 (0)