-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguage_des.go
87 lines (77 loc) · 2.81 KB
/
language_des.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"fmt"
"os"
"strings"
"golang.org/x/text/language"
)
var Des_map = map[string]map[language.Tag]string{
"init_cmd": {
language.English: "Please use the init command to initialize the configuration url",
language.SimplifiedChinese: "请使用init 命令初始化配置url",
},
"root_cmd_long": {
language.English: "go_webdav_client is an upload and download tool",
language.SimplifiedChinese: "go_webdav_client 是一个上传下载工具",
},
"upload_cmd_long": {
language.English: "Uploading files requires two parameters: local file path and webdav file path",
language.SimplifiedChinese: "上传文件 需要两个参数:本地文件路径 和 webdav文件路径",
},
"list_cmd_long": {
language.English: "List files and directories",
language.SimplifiedChinese: "列出文件及目录",
},
"del_cmd_long": {
language.English: "Delete files/delete folders support recursion",
language.SimplifiedChinese: "删除文件/删除文件夹 支持递归",
},
"mkdir_cmd_long": {
language.English: "Create folders to support multi-layer creation",
language.SimplifiedChinese: "建立文件夹 支持多层建立",
},
"download_cmd_long": {
language.English: "Downloading a file requires two parameters: local file path and webdav file path",
language.SimplifiedChinese: "下载文件 需要两个参数:本地文件路径 和 webdav文件路径",
},
"init_cmd_long": {
language.English: "Initializing url configuration requires remote https link (webdav)",
language.SimplifiedChinese: "初始化url配置 需要 远程https 链接(webdav)",
},
"init_url_flag_des": {
language.English: "The accessed url needs to be a webdav service",
language.SimplifiedChinese: "访问的url,需要是webdav服务",
},
"local_file_path_flag_des": {
language.English: "local file path",
language.SimplifiedChinese: "本地文件路径",
},
"remote_file_path_flag_des": {
language.English: "webdav file path",
language.SimplifiedChinese: "webdav文件路径",
},
}
func init_help_str(Des map[string]map[language.Tag]string, help_cmd string) string {
// 检测用户语言
langEnv := os.Getenv("LANG")
langTag := cleanLangTag(langEnv)
lang, _, err := language.ParseAcceptLanguage(langTag)
if err != nil {
fmt.Println(err)
}
// 获取对应语言的长描述
longDesc, exists := Des[help_cmd][lang[0]]
if !exists {
longDesc = Des[help_cmd][language.English] // 默认使用英语
}
return longDesc
}
// cleanLangTag 函数用于清理语言标签
func cleanLangTag(tag string) string {
tag = strings.Split(tag, ".")[0] // 去掉 .UTF-8 等后缀
tag = strings.ReplaceAll(tag, "_", "-") // 替换 _ 为 -
if tag == "zh-CN" {
tag = "zh-Hans"
}
return tag
}