-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathi18n.js
More file actions
206 lines (192 loc) · 7.22 KB
/
i18n.js
File metadata and controls
206 lines (192 loc) · 7.22 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
;(function () {
var STORAGE_KEY = "ruyiai-lang";
var LANG =
localStorage.getItem(STORAGE_KEY) ||
(navigator.language && navigator.language.startsWith("zh") ? "zh" : "en");
var i18n = {
zh: {
"nav.home": "首页",
"nav.projects": "项目",
"nav.contribute": "贡献",
"nav.docs": "文档",
"nav.community": "社区",
"nav.insights": "洞察",
"nav.about": "关于",
"nav.menu": "菜单",
"nav.compiler": "RuyiAI 编译器",
"nav.compilerDesc": "基于 MLIR 桥接 PyTorch 和 RISC-V",
"nav.operatorLang": "RuyiAI 算子编程语言",
"nav.operatorLangDesc": "面向 RISC-V 适配 Triton / TileLang",
"nav.operatorLib": "RuyiAI 算子库",
"nav.operatorLibDesc": "面向 RISC-V 的原生高性能算子库",
"nav.runtime": "RuyiAI 运行时环境",
"nav.runtimeDesc": "面向 RISC-V 各类扩展的统一运行时环境",
"nav.langZh": "中文",
"nav.langEn": "English",
"doc.toc": "目录",
"doc.onThisPage": "本页目录",
"doc.search": "搜索文档",
"doc.overview": "总览",
"doc.install": "安装方式",
"doc.tutorial": "使用教程",
"doc.contributorGuide": "贡献者指引",
"doc.codeStyle": "代码规范",
"doc.gitWorkflow": "Git 开源工作流程",
"doc.compiler": "RuyiAI 编译器",
"doc.rvvEnv": "RVV 环境",
"doc.imeDialect": "IME 方言",
"doc.gemmini": "Gemmini",
"doc.addPass": "添加 Pass",
"doc.buildMethods": "构建方法",
"doc.dynamicVector": "动态向量表示",
"doc.convOpt": "卷积优化",
"doc.convolutionVectorization": "卷积向量化",
"doc.addingOperators": "增加算子支持",
"doc.operatorLang": "RuyiAI 算子编程语言",
"doc.tritonOnRiscv": "Triton 的 RISC-V 适配",
"doc.debug": "调试",
"doc.irOutput": "中间表示输出",
"doc.tritonRiscvOverview": "triton-riscv 总览",
"doc.implementation": "实现方案",
"doc.operatorLib": "RuyiAI 算子库",
"doc.runtime": "RuyiAI 运行时环境",
"doc.insights": "洞察",
"doc.about": "关于",
"hero.subtitle": "面向 RISC-V 架构的<br />人工智能系统软件栈",
"hero.install": "立即安装",
"hero.tutorial": "使用教程",
"hero.overview": "项目架构",
"footer.privacy": "Privacy",
"footer.terms": "Terms"
},
en: {
"nav.home": "Home",
"nav.projects": "Projects",
"nav.contribute": "Contribute",
"nav.docs": "Docs",
"nav.community": "Community",
"nav.insights": "Insights",
"nav.about": "About",
"nav.menu": "Menu",
"nav.compiler": "RuyiAI Compiler",
"nav.compilerDesc": "MLIR-based bridge between PyTorch and RISC-V",
"nav.operatorLang": "RuyiAI Operator Language",
"nav.operatorLangDesc": "Triton / TileLang for RISC-V",
"nav.operatorLib": "RuyiAI Operator Library",
"nav.operatorLibDesc": "Native high-performance operator library for RISC-V",
"nav.runtime": "RuyiAI Runtime",
"nav.runtimeDesc": "Unified runtime for RISC-V extensions",
"nav.langZh": "中文",
"nav.langEn": "English",
"doc.toc": "Table of contents",
"doc.onThisPage": "On this page",
"doc.search": "Search docs",
"doc.overview": "Overview",
"doc.install": "Install",
"doc.tutorial": "Tutorial",
"doc.contributorGuide": "Contributor Guide",
"doc.codeStyle": "Code Style",
"doc.gitWorkflow": "Git Workflow",
"doc.compiler": "RuyiAI Compiler",
"doc.rvvEnv": "RVV Environment",
"doc.imeDialect": "IME Dialect",
"doc.gemmini": "Gemmini",
"doc.addPass": "Add Pass",
"doc.buildMethods": "Build Methods",
"doc.dynamicVector": "Dynamic Vector Representation",
"doc.convOpt": "Convolution Optimization",
"doc.convolutionVectorization": "Convolution Vectorization",
"doc.addingOperators": "Adding Operators",
"doc.operatorLang": "RuyiAI Operator Language",
"doc.tritonOnRiscv": "Triton on RISC-V",
"doc.debug": "Debug",
"doc.irOutput": "Intermediate Representation (IR) Output",
"doc.tritonRiscvOverview": "Triton RISC-V Overview",
"doc.implementation": "Implementation",
"doc.operatorLib": "RuyiAI Operator Library",
"doc.runtime": "RuyiAI Runtime",
"doc.insights": "Insights",
"doc.about": "About",
"hero.subtitle": "AI System Software Stack<br />for RISC-V Architecture",
"hero.install": "Get Started",
"hero.tutorial": "Tutorial",
"hero.overview": "Project Overview",
"footer.privacy": "Privacy",
"footer.terms": "Terms"
}
};
function getText(key) {
return (i18n[LANG] && i18n[LANG][key]) || i18n.zh[key] || key;
}
function applyLanguage() {
document.documentElement.lang = LANG === "zh" ? "zh-CN" : "en";
document.querySelectorAll("[data-i18n]").forEach(function (el) {
var key = el.getAttribute("data-i18n");
var text = getText(key);
if (text) {
if (el.getAttribute("aria-label") !== null) {
el.setAttribute("aria-label", text);
} else if (el.tagName === "INPUT" || el.tagName === "TEXTAREA") {
el.placeholder = text;
} else {
el.textContent = text;
}
}
});
document.querySelectorAll("[data-i18n-html]").forEach(function (el) {
var key = el.getAttribute("data-i18n-html");
var html = getText(key);
if (html) el.innerHTML = html;
});
var toggle = document.getElementById("navLangWrap");
if (toggle) toggle.classList.toggle("lang-toggle--en", LANG === "en");
if (typeof window.dispatchEvent === "function") {
window.dispatchEvent(
new CustomEvent("languagechange", { detail: { lang: LANG } })
);
}
}
function setLang(lang) {
if (lang !== "zh" && lang !== "en") return;
LANG = lang;
window.ruyiaiLang = LANG;
localStorage.setItem(STORAGE_KEY, LANG);
applyLanguage();
}
function initSwitcher() {
var actions = document.querySelector(".nav__actions");
if (!actions) return;
var existing = document.getElementById("navLangWrap");
if (existing) return;
var wrap = document.createElement("button");
wrap.id = "navLangWrap";
wrap.type = "button";
wrap.className =
"lang-toggle" + (LANG === "en" ? " lang-toggle--en" : "");
wrap.setAttribute("aria-label", "Switch language");
wrap.innerHTML =
'<span class="lang-toggle__track">' +
'<span class="lang-toggle__label lang-toggle__label--zh">中</span>' +
'<span class="lang-toggle__label lang-toggle__label--en">En</span>' +
'<span class="lang-toggle__thumb"></span>' +
"</span>";
wrap.addEventListener("click", function () {
var next = LANG === "zh" ? "en" : "zh";
setLang(next);
wrap.classList.toggle("lang-toggle--en", next === "en");
});
actions.insertBefore(wrap, actions.firstChild);
applyLanguage();
}
function run() {
initSwitcher();
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", run);
} else {
run();
}
window.ruyiaiLang = LANG;
window.ruyiaiSetLang = setLang;
window.ruyiaiGetText = getText;
})();