Skip to content

Commit

Permalink
Update i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
qianlifeng committed Nov 2, 2024
1 parent 149c266 commit dd7db57
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -764,19 +764,44 @@ class WoxLauncherController extends GetxController {
}

/// update active actions based on active result and reset active action index to 0
void resetActiveAction(String traceId, String reason) {
void resetActiveAction(String traceId, String reason, {bool remainIndex = false}) {
var activeQueryResult = getActiveResult();
if (activeQueryResult == null || activeQueryResult.actions.isEmpty) {
Logger.instance.info(traceId, "update active actions, reason: $reason, current active result: null");
activeActionIndex.value = -1;
actions.clear();
return;
}

Logger.instance.info(traceId, "update active actions, reason: $reason, current active result: ${activeQueryResult.title.value}, active action: ${activeQueryResult.actions.first.name.value}");

String? previousActionName;
if (remainIndex && actions.isNotEmpty && activeActionIndex.value >= 0 && activeActionIndex.value < actions.length) {
previousActionName = actions[activeActionIndex.value].name.value;
}

final filterText = actionTextFieldController.text;
if (filterText.isNotEmpty) {
var filteredActions = activeQueryResult.actions.where((element) {
return isFuzzyMatch(traceId, element.name.value, filterText);
}).toList();
actions.assignAll(filteredActions);
} else {
Logger.instance.info(traceId, "update active actions, reason: $reason, current active result: ${activeQueryResult.title.value}, active action: ${activeQueryResult.actions.first.name.value}");
activeActionIndex.value = 0;
actions.assignAll(activeQueryResult.actions);
}

// remain the same action index
if (remainIndex && previousActionName != null) {
final newIndex = actions.indexWhere((action) => action.name.value == previousActionName);
if (newIndex != -1) {
activeActionIndex.value = newIndex;
} else {
activeActionIndex.value = 0;
}
} else {
activeActionIndex.value = 0;
}

updateToolbarByActiveAction(traceId);
}

Expand Down Expand Up @@ -840,11 +865,11 @@ class WoxLauncherController extends GetxController {
result.tails.assignAll(refreshResult.tails);
result.actions.assignAll(refreshResult.actions);

// only update preview and toolbar when current result is active
// only update preview and toolbar when current result is active
final resultIndex = results.indexWhere((element) => element.id == result.id);
if (isResultActiveByIndex(resultIndex)) {
currentPreview.value = result.preview;
resetActiveAction(traceId, "refresh active result");
resetActiveAction(traceId, "refresh active result", remainIndex: true);
}

result.contextData = refreshResult.contextData;
Expand Down
15 changes: 6 additions & 9 deletions Wox/plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func (m *Manager) GetResultForFailedQuery(ctx context.Context, pluginMetadata Me
icon := pluginIcon.OverlayFullPercentage(overlayIcon, 0.6)

return QueryResult{
Title: fmt.Sprintf("%s query failed", pluginMetadata.Name),
Title: fmt.Sprintf(i18n.GetI18nManager().TranslateWox(ctx, "plugin_manager_query_failed"), pluginMetadata.Name),
SubTitle: util.EllipsisEnd(err.Error(), 20),
Icon: icon,
Preview: WoxPreview{
Expand All @@ -451,18 +451,16 @@ func (m *Manager) addDefaultActions(ctx context.Context, pluginInstance *Instanc
if query.Type == QueryTypeInput {
if result.Group == "" {
if setting.GetSettingManager().IsFavoriteResult(ctx, pluginInstance.Metadata.Id, result.Title, result.SubTitle) {
// add "Remove from favorite" action
result.Actions = append(result.Actions, QueryResultAction{
Name: "Remove from favorite",
Name: "i18n:plugin_manager_remove_from_favorite",
Icon: RemoveFromFavIcon,
Action: func(ctx context.Context, actionContext ActionContext) {
setting.GetSettingManager().RemoveFavoriteResult(ctx, pluginInstance.Metadata.Id, result.Title, result.SubTitle)
},
})
} else {
// add "Add to favorite" action
result.Actions = append(result.Actions, QueryResultAction{
Name: "Add to favorite",
Name: "i18n:plugin_manager_add_to_favorite",
Icon: AddToFavIcon,
Action: func(ctx context.Context, actionContext ActionContext) {
setting.GetSettingManager().AddFavoriteResult(ctx, pluginInstance.Metadata.Id, result.Title, result.SubTitle)
Expand All @@ -471,7 +469,6 @@ func (m *Manager) addDefaultActions(ctx context.Context, pluginInstance *Instanc
}
}
}

return result
}

Expand Down Expand Up @@ -627,11 +624,11 @@ func (m *Manager) PolishResult(ctx context.Context, pluginInstance *Instance, qu
func (m *Manager) formatFileListPreview(ctx context.Context, filePaths []string) string {
totalFiles := len(filePaths)
if totalFiles == 0 {
return i18n.GetI18nManager().TranslateWox(ctx, "i18n:selection_no_files_selected")
return i18n.GetI18nManager().TranslateWox(ctx, "selection_no_files_selected")
}

var sb strings.Builder
sb.WriteString(fmt.Sprintf(i18n.GetI18nManager().TranslateWox(ctx, "i18n:selection_selected_files_count"), totalFiles))
sb.WriteString(fmt.Sprintf(i18n.GetI18nManager().TranslateWox(ctx, "selection_selected_files_count"), totalFiles))
sb.WriteString("\n\n")

maxDisplayFiles := 10
Expand All @@ -641,7 +638,7 @@ func (m *Manager) formatFileListPreview(ctx context.Context, filePaths []string)
} else {
remainingFiles := totalFiles - maxDisplayFiles
sb.WriteString("\n")
sb.WriteString(fmt.Sprintf(i18n.GetI18nManager().TranslateWox(ctx, "i18n:selection_remaining_files_not_shown"), remainingFiles))
sb.WriteString(fmt.Sprintf(i18n.GetI18nManager().TranslateWox(ctx, "selection_remaining_files_not_shown"), remainingFiles))
break
}
}
Expand Down
6 changes: 5 additions & 1 deletion Wox/resource/lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,9 @@
"plugin_calculator_recalculate": "Recalculate",
"plugin_calculator_input_expression": "Input expression to calculate",
"plugin_file_open": "Open",
"plugin_file_open_containing_folder": "Open containing folder"
"plugin_file_open_containing_folder": "Open containing folder",
"plugin_manager_query_failed": "%s query failed",
"plugin_manager_remove_from_favorite": "Remove from favorite",
"plugin_manager_add_to_favorite": "Add to favorite",
"plugin_manager_invalid_query_type": "Invalid query type"
}
6 changes: 5 additions & 1 deletion Wox/resource/lang/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,9 @@
"plugin_calculator_recalculate": "重新计算",
"plugin_calculator_input_expression": "输入表达式进行计算",
"plugin_file_open": "打开",
"plugin_file_open_containing_folder": "打开所在文件夹"
"plugin_file_open_containing_folder": "打开所在文件夹",
"plugin_manager_query_failed": "%s 查询失败",
"plugin_manager_remove_from_favorite": "从收藏夹移除",
"plugin_manager_add_to_favorite": "添加到收藏夹",
"plugin_manager_invalid_query_type": "无效的查询类型"
}

0 comments on commit dd7db57

Please sign in to comment.