Skip to content

Commit c882c2d

Browse files
authored
fix: Fix i18n bug (opentiny#229)
1 parent 092df38 commit c882c2d

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

base/src/main/java/com/tinyengine/it/controller/I18nEntryController.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,20 @@ public class I18nEntryController {
7070
private I18nEntryService i18nEntryService;
7171

7272
/**
73-
* Gets all i 18 n entries.
73+
* Gets all i 18 n entries by app.
7474
*
75-
* @return 获取国际化词条列表 all i 18 n entries
75+
* @return 获取国际化词条列表 i 18 n entries
7676
*/
77-
@Operation(summary = "获取国际化词条列表", description = "获取国际化词条列表", responses = {
77+
@Operation(summary = "通过app获取国际化词条列表", description = "通过app获取国际化词条列表", responses = {
7878
@ApiResponse(responseCode = "200", description = "返回信息",
7979
content = @Content(mediaType = "application/json", schema = @Schema())),
8080
@ApiResponse(responseCode = "400", description = "请求失败")
8181
})
8282
@SystemControllerLog(description = "获取国际化词条列表")
8383
@GetMapping("/i18n/entries")
84-
public Result<I18nEntryListResult> getAllI18nEntries() {
85-
I18nEntryListResult i18nEntriesList = i18nEntryService.findAllI18nEntry();
84+
public Result<I18nEntryListResult> getI18nEntriesByApp( @RequestParam(value = "host", required = false) Integer host,
85+
@RequestParam(value = "host_type", required = false) String hostType) {
86+
I18nEntryListResult i18nEntriesList = i18nEntryService.findI18nEntryByApp(host, hostType);
8687
return Result.success(i18nEntriesList);
8788
}
8889

base/src/main/java/com/tinyengine/it/service/app/I18nEntryService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,11 @@ public interface I18nEntryService {
124124
* @throws Exception the exception
125125
*/
126126
Result<FileResult> readFilesAndbulkCreate(String lang, MultipartFile file, int host) throws Exception;
127+
128+
/**
129+
* 通过app查询表t_i18n_entry所有信息
130+
*
131+
* @return the 18 n entry list result
132+
*/
133+
I18nEntryListResult findI18nEntryByApp(Integer host, String hostType);
127134
}

base/src/main/java/com/tinyengine/it/service/app/impl/I18nEntryServiceImpl.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,35 @@ public Result<FileResult> readFilesAndbulkCreate(String lang, MultipartFile file
375375
return Result.success(i18nFileResult);
376376
}
377377

378+
/**
379+
* 通过app查询表t_i18n_entry所有信息
380+
*
381+
* @return the 18 n entry list result
382+
*/
383+
@Override
384+
public I18nEntryListResult findI18nEntryByApp(Integer host, String hostType) {
385+
I18nEntryListResult i18nEntriesListResult = new I18nEntryListResult();
386+
// 获取所属应用/区块的 语言列表 getHostLangs
387+
List<I18nLang> i18nLangsList = getHostLangs();
388+
if (i18nLangsList == null || i18nLangsList.isEmpty()) {
389+
return i18nEntriesListResult;
390+
}
391+
// 获取词条列表
392+
List<I18nEntryDto> i18nEntriesList = i18nEntryMapper.findI18nEntriesByHostandHostType(host, hostType);
393+
if (i18nEntriesList == null) {
394+
return i18nEntriesListResult;
395+
}
396+
// 格式化词条列表
397+
SchemaI18n messages = formatEntriesList(i18nEntriesList);
398+
List<I18nLang> i18nLangsListTemp = i18nLangsList.stream()
399+
.map(i18nLang -> new I18nLang(i18nLang.getLang(), i18nLang.getLabel()))
400+
.collect(Collectors.toList());
401+
402+
i18nEntriesListResult.setI18nLangsList(i18nLangsListTemp);
403+
i18nEntriesListResult.setMessages(messages);
404+
return i18nEntriesListResult;
405+
}
406+
378407
/**
379408
* 批量创建或修改
380409
*
@@ -449,7 +478,7 @@ public List<EntriesItem> parseZipFileStream(MultipartFile file) throws Exception
449478
// 解压ZIP文件并处理
450479
List<FileInfo> fileInfos = Utils.unzip(file);
451480
for (FileInfo fileInfo : fileInfos) {
452-
entriesItems = parseZip(fileInfo);
481+
entriesItems.addAll(parseZip(fileInfo));
453482
}
454483
return entriesItems;
455484
}
@@ -530,7 +559,7 @@ private EntriesItem setLang(String fileName) {
530559
} else {
531560
name = fileName.substring(0, lastDotIndex); // 返回不带扩展名的文件名
532561
}
533-
if (Enums.I18nFileName.EN_US.getValue().equals(name)) {
562+
if (name.contains(Enums.I18nFileName.EN_US.getValue())) {
534563
entriesItem.setLang(2);
535564
} else {
536565
entriesItem.setLang(1);

0 commit comments

Comments
 (0)