feat(file): wire file shortcuts into i18n with en-US/zh-CN locales

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
farmyobutu5233 2026-07-05 10:50:12 +00:00
parent 27053f66d4
commit 40bfc64b8b
4 changed files with 70 additions and 33 deletions

View File

@ -34,6 +34,12 @@
"cmd.dataset.view.short": "View a repository's dataset",
"cmd.doctor.long": "Run local diagnostics for gitlink-cli configuration, authentication, repository context and API connectivity.",
"cmd.doctor.short": "Diagnose gitlink-cli environment problems",
"cmd.file.create.short": "Create a new file in the repository",
"cmd.file.delete.short": "Delete a file from the repository",
"cmd.file.search.short": "Search files in the repository by name",
"cmd.file.short": "Repository file content operations",
"cmd.file.update.short": "Update an existing file in the repository",
"cmd.file.view.short": "View the contents of a file",
"cmd.issue.batch_close.long": "Close filtered issues in bulk.\n\nThis command defaults to dry-run mode and only prints matching issues.\nPass --yes to execute remote close operations. Use restrictive filters and a small limit.\n\nExamples:\n gitlink-cli issue +batch-close --owner Gitlink --repo gitlink-cli --older-than-days 60 --limit 20\n gitlink-cli issue +batch-close --owner Gitlink --repo gitlink-cli --older-than-days 60 --limit 20 --yes",
"cmd.issue.batch_close.short": "Close filtered issues in bulk. Defaults to dry-run; pass --yes to execute.",
"cmd.issue.batch_label.long": "Add a label to filtered issues in bulk.\n\nThis command defaults to dry-run mode and only prints matching issues.\nPass --yes to execute remote label operations. The current implementation does not fake label writes when the API endpoint is unavailable.\n\nExamples:\n gitlink-cli issue +batch-label --owner Gitlink --repo gitlink-cli --add-label stale --older-than-days 30 --limit 50\n gitlink-cli issue +batch-label --owner Gitlink --repo gitlink-cli --add-label stale --older-than-days 30 --limit 50 --yes",
@ -145,6 +151,14 @@
"flag.description": "Description",
"flag.doctor.skip_network": "Skip authenticated API connectivity checks",
"flag.dry_run": "Preview the request without creating it",
"flag.file.branch": "Branch to commit to",
"flag.file.content": "File content",
"flag.file.content_file": "Read file content from a local file",
"flag.file.message": "Commit message",
"flag.file.new_branch": "Create a new branch from --branch for the commit",
"flag.file.path": "File path",
"flag.file.raw": "Print only the decoded file content",
"flag.file.ref": "Branch, tag, or commit SHA (defaults to the default branch)",
"flag.format": "Output format: json, table, yaml (default: table)",
"flag.issue.add_label": "Label to add to each matching issue",
"flag.issue.assignee": "Assignee login",

View File

@ -34,6 +34,12 @@
"cmd.dataset.view.short": "查看仓库数据集",
"cmd.doctor.long": "诊断 gitlink-cli 的配置、认证、仓库上下文和 API 连通性问题。",
"cmd.doctor.short": "诊断 gitlink-cli 环境问题",
"cmd.file.create.short": "在仓库中创建文件",
"cmd.file.delete.short": "删除仓库中的文件",
"cmd.file.search.short": "按文件名搜索仓库文件",
"cmd.file.short": "仓库文件内容操作",
"cmd.file.update.short": "更新仓库中的文件",
"cmd.file.view.short": "查看文件内容",
"cmd.issue.batch_close.long": "批量关闭筛选后的议题。\n\n该命令默认处于 dry-run 模式,只打印匹配的议题。\n传入 --yes 后执行远端关闭操作。请使用严格筛选条件和较小 limit。\n\n示例\n gitlink-cli issue +batch-close --owner Gitlink --repo gitlink-cli --older-than-days 60 --limit 20\n gitlink-cli issue +batch-close --owner Gitlink --repo gitlink-cli --older-than-days 60 --limit 20 --yes",
"cmd.issue.batch_close.short": "批量关闭筛选后的议题。默认 dry-run传入 --yes 后执行。",
"cmd.issue.batch_label.long": "给筛选后的议题批量添加标签。\n\n该命令默认处于 dry-run 模式,只打印匹配的议题。\n传入 --yes 后执行远端标签操作。当前实现不会在 API 端点不可用时伪造写入结果。\n\n示例\n gitlink-cli issue +batch-label --owner Gitlink --repo gitlink-cli --add-label stale --older-than-days 30 --limit 50\n gitlink-cli issue +batch-label --owner Gitlink --repo gitlink-cli --add-label stale --older-than-days 30 --limit 50 --yes",
@ -145,6 +151,14 @@
"flag.description": "描述",
"flag.doctor.skip_network": "跳过需要访问 GitLink 的认证连通性检查",
"flag.dry_run": "预览请求,不实际创建",
"flag.file.branch": "提交到的分支",
"flag.file.content": "文件内容",
"flag.file.content_file": "从本地文件读取内容",
"flag.file.message": "提交信息",
"flag.file.new_branch": "从 --branch 新建分支并提交",
"flag.file.path": "文件路径",
"flag.file.raw": "仅输出解码后的文件正文",
"flag.file.ref": "分支、标签或提交 SHA默认使用默认分支",
"flag.format": "输出格式json、table、yaml默认table",
"flag.issue.add_label": "要添加到每个匹配议题的标签",
"flag.issue.assignee": "负责人登录名",

View File

@ -6,32 +6,41 @@ import (
"net/url"
"os"
"github.com/gitlink-org/gitlink-cli/internal/i18n"
"github.com/gitlink-org/gitlink-cli/shortcuts/common"
)
// Shortcuts returns all file shortcuts.
func Shortcuts() []*common.Shortcut {
func Shortcuts(translators ...*i18n.Translator) []*common.Shortcut {
tr := shortcutTranslator(translators...)
return []*common.Shortcut{
viewShortcut(),
searchShortcut(),
writeShortcut("create", "Create a new file in the repository"),
writeShortcut("update", "Update an existing file in the repository"),
deleteShortcut(),
viewShortcut(tr),
searchShortcut(tr),
writeShortcut(tr, "create"),
writeShortcut(tr, "update"),
deleteShortcut(tr),
}
}
func refFlag() common.Flag {
return common.Flag{Name: "ref", Usage: "Branch, tag, or commit SHA (defaults to the default branch)"}
func shortcutTranslator(translators ...*i18n.Translator) *i18n.Translator {
if len(translators) > 0 && translators[0] != nil {
return translators[0]
}
return i18n.Default()
}
func viewShortcut() *common.Shortcut {
func refFlag(tr *i18n.Translator) common.Flag {
return common.Flag{Name: "ref", Usage: tr.T("flag.file.ref")}
}
func viewShortcut(tr *i18n.Translator) *common.Shortcut {
return &common.Shortcut{
Name: "view",
Description: "View the contents of a file",
Description: tr.T("cmd.file.view.short"),
Flags: []common.Flag{
{Name: "path", Short: "p", Usage: "File path", Required: true},
refFlag(),
{Name: "raw", Usage: "Print only the decoded file content", Bool: true},
{Name: "path", Short: "p", Usage: tr.T("flag.file.path"), Required: true},
refFlag(tr),
{Name: "raw", Usage: tr.T("flag.file.raw"), Bool: true},
},
Run: func(ctx *common.RuntimeContext) error {
if err := ctx.ResolveOwnerRepo(); err != nil {
@ -58,13 +67,13 @@ func viewShortcut() *common.Shortcut {
}
}
func searchShortcut() *common.Shortcut {
func searchShortcut(tr *i18n.Translator) *common.Shortcut {
return &common.Shortcut{
Name: "search",
Description: "Search files in the repository by name",
Description: tr.T("cmd.file.search.short"),
Flags: []common.Flag{
{Name: "keyword", Short: "k", Usage: "Search keyword", Required: true},
refFlag(),
{Name: "keyword", Short: "k", Usage: tr.T("flag.search.keyword"), Required: true},
refFlag(tr),
},
Run: func(ctx *common.RuntimeContext) error {
if err := ctx.ResolveOwnerRepo(); err != nil {
@ -88,17 +97,17 @@ func searchShortcut() *common.Shortcut {
}
}
func writeShortcut(action, description string) *common.Shortcut {
func writeShortcut(tr *i18n.Translator, action string) *common.Shortcut {
return &common.Shortcut{
Name: action,
Description: description,
Description: tr.T("cmd.file." + action + ".short"),
Flags: []common.Flag{
{Name: "path", Short: "p", Usage: "File path", Required: true},
{Name: "content", Short: "c", Usage: "File content"},
{Name: "content-file", Usage: "Read file content from a local file"},
{Name: "branch", Short: "b", Usage: "Branch to commit to", Required: true},
{Name: "new-branch", Usage: "Create a new branch from --branch for the commit"},
{Name: "message", Short: "m", Usage: "Commit message"},
{Name: "path", Short: "p", Usage: tr.T("flag.file.path"), Required: true},
{Name: "content", Short: "c", Usage: tr.T("flag.file.content")},
{Name: "content-file", Usage: tr.T("flag.file.content_file")},
{Name: "branch", Short: "b", Usage: tr.T("flag.file.branch"), Required: true},
{Name: "new-branch", Usage: tr.T("flag.file.new_branch")},
{Name: "message", Short: "m", Usage: tr.T("flag.file.message")},
},
Run: func(ctx *common.RuntimeContext) error {
if err := ctx.ResolveOwnerRepo(); err != nil {
@ -144,15 +153,15 @@ func writeShortcut(action, description string) *common.Shortcut {
}
}
func deleteShortcut() *common.Shortcut {
func deleteShortcut(tr *i18n.Translator) *common.Shortcut {
return &common.Shortcut{
Name: "delete",
Description: "Delete a file from the repository",
Description: tr.T("cmd.file.delete.short"),
Flags: []common.Flag{
{Name: "path", Short: "p", Usage: "File path", Required: true},
{Name: "branch", Short: "b", Usage: "Branch to commit to", Required: true},
{Name: "new-branch", Usage: "Create a new branch from --branch for the commit"},
{Name: "message", Short: "m", Usage: "Commit message"},
{Name: "path", Short: "p", Usage: tr.T("flag.file.path"), Required: true},
{Name: "branch", Short: "b", Usage: tr.T("flag.file.branch"), Required: true},
{Name: "new-branch", Usage: tr.T("flag.file.new_branch")},
{Name: "message", Short: "m", Usage: tr.T("flag.file.message")},
},
Run: func(ctx *common.RuntimeContext) error {
if err := ctx.ResolveOwnerRepo(); err != nil {

View File

@ -54,7 +54,7 @@ func RegisterAll(root *cobra.Command, translators ...*i18n.Translator) {
"ci": ci.Shortcuts(tr),
"compare": compare.Shortcuts(),
"dataset": dataset.Shortcuts(tr),
"file": file.Shortcuts(),
"file": file.Shortcuts(tr),
"webhook": webhook.Shortcuts(tr),
"wiki": wiki.Shortcuts(),
"health": health.Shortcuts(tr),
@ -80,7 +80,7 @@ func RegisterAll(root *cobra.Command, translators ...*i18n.Translator) {
"ci": tr.T("cmd.ci.short"),
"compare": "Compare branches, tags, or commits",
"dataset": tr.T("cmd.dataset.short"),
"file": "Repository file content operations",
"file": tr.T("cmd.file.short"),
"webhook": tr.T("cmd.webhook.short"),
"wiki": "Wiki page management",
"health": "Project health data collection",