Skip to content

Commit

Permalink
✨ version 1.7.35
Browse files Browse the repository at this point in the history
add i18n support for completion prompts
  • Loading branch information
RF-Tar-Railt committed Nov 18, 2023
1 parent 6dbe1f8 commit 8573159
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 更新日志

## Alconna 1.7.35

### 改进

为 completion 下提示列出的选中符号和未选中符号添加 i18n 支持

## Alconna 1.7.34

### 修复
Expand Down
2 changes: 1 addition & 1 deletion src/arclet/alconna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/arclet/alconna/_internal/_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/arclet/alconna/_internal/_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion src/arclet/alconna/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 2 additions & 0 deletions src/arclet/alconna/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
},
Expand Down
2 changes: 2 additions & 0 deletions src/arclet/alconna/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
},
"completion": {
"node": "以下是建议的输入:",
"prompt_select": ">>",
"prompt_other": "*",
"prompt_empty": "没有可用的补全提示",
"prompt_unavailable": "选择的补全提示不可用于输入"
},
Expand Down

0 comments on commit 8573159

Please sign in to comment.