irongit

A Neovim plugin enabling you to solve LeetCode problems.

leetcode.nvim/lua/leetcode/translator.lua
113 lines3.7 KBLua
1local config = require("leetcode.config")
2
3---@class lc.translate
4local translate = {
5 ["problems"] = "题库",
6 ["statistics"] = "统计",
7 ["cookie"] = "Cookie",
8 ["cache"] = "缓存",
9 ["exit"] = "退出",
10 ["back"] = "后退",
11 ["menu"] = "菜单",
12 ["loading..."] = "加载中...",
13 ["signed in as"] = "已登录为",
14 ["update"] = "更新",
15 ["list"] = "列表",
16 ["random"] = "随机",
17 ["daily"] = "每日",
18 ["delete / sign out"] = "删除 / 退出",
19 ["sign in"] = "登录",
20 ["sign in (by cookie)"] = "使用Cookie登录",
21 ["enter cookie"] = "输入 Cookie",
22 ["sign-in successful"] = "登录成功",
23 ["sign-in failed"] = "登录失败",
24 ["hints"] = "提示",
25 ["of"] = "的",
26 ["run"] = "运行",
27 ["submit"] = "提交",
28 ["result"] = "执行结果",
29 ["testcases"] = "测试用例",
30 ["topics"] = "相关标签",
31 ["premium"] = "高级",
32 ["similar questions"] = "相似题目",
33 ["no similar questions available"] = "没有类似的问题可用",
34 ["no topics available"] = "没有可用的主题",
35 ["no hints available"] = "没有提示可用",
36 ["drawn question is for premium users only. please try again"] = "抽选的问题仅供高级用户使用。请再试一次。",
37 ["please verify your email address in order to use your account"] = "请验证您的电子邮件地址以便使用您的账户",
38 ["use testcase"] = "添加到测试用例",
39 ["available languages"] = "可用语言",
40 ["languages"] = "语言",
41 ["language already set to"] = "语言已设置为",
42 ["skills"] = "技能",
43 ["runtime"] = "时间",
44 ["runtime error"] = "执行出错",
45 ["memory"] = "内存",
46 ["beats"] = "击败",
47 ["testcases passed"] = "个通过的测试用例",
48 ["last executed input"] = "最后执行的输入",
49 ["reset"] = "重置",
50 ["input"] = "输入",
51 ["output"] = "输出",
52 ["expected"] = "预期结果",
53 ["invalid"] = "无效",
54 ["question info"] = "问题信息",
55 ["select a question"] = "选择一个问题",
56 ["question is for premium users only"] = "问题仅限高级用户使用",
57 ["no questions opened"] = "没有打开的问题",
58 ["no current question found"] = "未找到当前问题",
59 ["you're now signed out"] = "您现在已注销",
60 ["you have attempted to run code too soon"] = "你的提交过于频繁,请稍候重试。",
61 ["stdout"] = "标准输出",
62 ["submissions"] = "过去一年共提交",
63 ["active days"] = "累计提交天数",
64 ["max streak"] = "连续提交",
65 ["more challenges"] = "更多挑战",
66 ["session"] = "进度",
67
68 -- difficulty
69 ["all"] = "所有",
70 ["easy"] = "简单",
71 ["medium"] = "中等",
72 ["hard"] = "困难",
73
74 -- status_msg
75 ["accepted"] = "通过",
76 ["wrong answer"] = "解答错误",
77 ["compile error"] = "编译出错",
78 ["time limit exceeded"] = "超出时间限制",
79 ["output limit exceeded"] = "超出输出限制",
80 -- ["internal error"] = "internal error",
81 ["memory limit exceeded"] = "超出内存限制",
82 ["invalid testcase"] = "测试用例非有效值",
83
84 -- err
85 ["http error"] = "HTTP 错误",
86 ["curl failed"] = "curl 失败",
87
88 -- interpreter status
89 ["pending…"] = "运行中…",
90 ["judging…"] = "判题中…",
91 ["finished"] = "完成",
92 ["failed"] = "失败",
93}
94
95---@param text string
96local function t(text)
97 local keys = vim.tbl_map(function(key)
98 return key:lower()
99 end, vim.tbl_keys(translate))
100
101 if not vim.tbl_contains(keys, text:lower()) then
102 return text
103 end
104 return translate[text:lower()]
105end
106
107return function(text)
108 if config.translator and type(text) == "string" then
109 return t(text)
110 else
111 return text
112 end
113end