From 8573159ec520303143a2d5a5b35bdce7ad5ba1bc Mon Sep 17 00:00:00 2001 From: RF-Tar-Railt <3165388245@qq.com> Date: Sat, 18 Nov 2023 12:06:54 +0800 Subject: [PATCH] :sparkles: version 1.7.35 add i18n support for completion prompts --- CHANGELOG.md | 6 ++++++ src/arclet/alconna/__init__.py | 2 +- src/arclet/alconna/_internal/_analyser.py | 4 ++-- src/arclet/alconna/_internal/_handlers.py | 3 ++- src/arclet/alconna/completion.py | 4 +++- src/arclet/alconna/i18n/en-US.json | 2 ++ src/arclet/alconna/i18n/zh-CN.json | 2 ++ 7 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbd22033..76ee4943 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 更新日志 +## Alconna 1.7.35 + +### 改进 + +为 completion 下提示列出的选中符号和未选中符号添加 i18n 支持 + ## Alconna 1.7.34 ### 修复 diff --git a/src/arclet/alconna/__init__.py b/src/arclet/alconna/__init__.py index f9e4ad49..47121364 100644 --- a/src/arclet/alconna/__init__.py +++ b/src/arclet/alconna/__init__.py @@ -50,7 +50,7 @@ from .typing import UnpackVar as UnpackVar from .typing import Up as Up -__version__ = "1.7.34" +__version__ = "1.7.35" # backward compatibility Arpamar = Arparma diff --git a/src/arclet/alconna/_internal/_analyser.py b/src/arclet/alconna/_internal/_analyser.py index 006805f1..8ef80671 100644 --- a/src/arclet/alconna/_internal/_analyser.py +++ b/src/arclet/alconna/_internal/_analyser.py @@ -394,14 +394,14 @@ def export( self, argv: Argv[TDC], fail: bool = False, - exception: BaseException | None = None, + exception: Exception | None = None, ) -> Arparma[TDC]: """创建 `Arparma` 解析结果, 其一定是一次解析的最后部分 Args: argv (Argv[TDC]): 命令行参数 fail (bool, optional): 是否解析失败. Defaults to False. - exception (BaseException | None, optional): 解析失败时的异常. Defaults to None. + exception (Exception | None, optional): 解析失败时的异常. Defaults to None. """ result = Arparma(self.command.path, argv.origin, not fail, self.header_result) if fail: diff --git a/src/arclet/alconna/_internal/_handlers.py b/src/arclet/alconna/_internal/_handlers.py index 07cf1cd9..659ad839 100644 --- a/src/arclet/alconna/_internal/_handlers.py +++ b/src/arclet/alconna/_internal/_handlers.py @@ -680,8 +680,9 @@ def handle_completion(analyser: Analyser, argv: Argv, trigger: str | None = None if res := prompt(analyser, argv, trigger): if comp_ctx.get(None): raise PauseTriggered(res, trigger) + prompt_other = lang.require("completion", "prompt_other") output_manager.send( analyser.command.name, - lambda: f"{lang.require('completion', 'node')}\n* " + "\n* ".join([i.text for i in res]), + lambda: f"{lang.require('completion', 'node')}\n{prompt_other} " + f"\n{prompt_other} ".join([i.text for i in res]), ) return analyser.export(argv, True, SpecialOptionTriggered("completion")) # type: ignore diff --git a/src/arclet/alconna/completion.py b/src/arclet/alconna/completion.py index 2226362b..62708af4 100644 --- a/src/arclet/alconna/completion.py +++ b/src/arclet/alconna/completion.py @@ -183,7 +183,9 @@ def exit(self): def lines(self): """获取补全选项的文本列表。""" - return [f"{'>>' if self.index == index else '*'} {sug.text}" for index, sug in enumerate(self.prompts)] + select = lang.require("completion", "prompt_select") + other = lang.require("completion", "prompt_other") + return [f"{select if self.index == index else other} {sug.text}" for index, sug in enumerate(self.prompts)] def __repr__(self): return f"{lang.require('completion', 'node')}\n" + "\n".join(self.lines()) diff --git a/src/arclet/alconna/i18n/en-US.json b/src/arclet/alconna/i18n/en-US.json index 328d4691..02597d57 100644 --- a/src/arclet/alconna/i18n/en-US.json +++ b/src/arclet/alconna/i18n/en-US.json @@ -5,6 +5,8 @@ }, "completion": { "node": "suggest input follows:", + "prompt_select": ">>", + "prompt_other": "*", "prompt_empty": "No prompt available.", "prompt_unavailable": "This prompt cannot be used." }, diff --git a/src/arclet/alconna/i18n/zh-CN.json b/src/arclet/alconna/i18n/zh-CN.json index 94376939..ea67bff6 100644 --- a/src/arclet/alconna/i18n/zh-CN.json +++ b/src/arclet/alconna/i18n/zh-CN.json @@ -5,6 +5,8 @@ }, "completion": { "node": "以下是建议的输入:", + "prompt_select": ">>", + "prompt_other": "*", "prompt_empty": "没有可用的补全提示", "prompt_unavailable": "选择的补全提示不可用于输入" },