Skip to content

Commit 8fc2443

Browse files
committed
feat: add english document
1 parent e9aebd1 commit 8fc2443

File tree

11 files changed

+864
-1009
lines changed

11 files changed

+864
-1009
lines changed

.vitepress/config.mts

Lines changed: 146 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { defineConfig } from 'vitepress'
22
import type { DefaultTheme } from 'vitepress'
3-
import llmstxt from 'vitepress-plugin-llms'
43
import cangjie from './cangjie.tmLanguage.json'
54

6-
const GUIDES: DefaultTheme.NavItemWithLink[] = [
5+
const zhGuides: DefaultTheme.NavItemWithLink[] = [
76
{ text: '简介', link: '/guide/' },
87
{ text: '快速开始', link: '/guide/quick_start' },
98
{ text: '安装', link: '/guide/install' },
@@ -12,10 +11,117 @@ const GUIDES: DefaultTheme.NavItemWithLink[] = [
1211
{ text: 'LLM', link: '/guide/llm' },
1312
]
1413

14+
const enGuides: DefaultTheme.NavItemWithLink[] = [
15+
{ text: 'Introduction', link: '/en/guide/' },
16+
{ text: 'Quick Start', link: '/en/guide/quick_start' },
17+
{ text: 'Installation', link: '/en/guide/install' },
18+
{ text: 'Command Line', link: '/en/guide/command_line' },
19+
{ text: 'Limitations', link: '/en/guide/limitation' },
20+
{ text: 'LLM', link: '/en/guide/llm' },
21+
]
22+
1523
export default defineConfig({
1624
title: "cjbind",
17-
lang: "zh-CN",
1825
description: "自动生成仓颉到 C 库的 FFI 绑定代码",
26+
27+
locales: {
28+
root: {
29+
label: '简体中文',
30+
lang: 'zh-CN',
31+
themeConfig: {
32+
nav: [
33+
{
34+
text: '指南',
35+
items: [{ items: zhGuides }],
36+
},
37+
],
38+
sidebar: {
39+
'/': [
40+
{
41+
text: '指南',
42+
items: zhGuides,
43+
},
44+
],
45+
},
46+
editLink: {
47+
pattern: 'https://github.com/cjbind/cjbind-docs/edit/master/:path',
48+
text: '在 GitHub 上编辑本页',
49+
},
50+
footer: {
51+
message: '以 MIT 许可证发布',
52+
copyright: `版权所有 © 2024 - ${new Date().getFullYear()} Zxilly`,
53+
},
54+
docFooter: {
55+
prev: '上一页',
56+
next: '下一页',
57+
},
58+
outline: {
59+
label: '目录',
60+
level: 'deep'
61+
},
62+
langMenuLabel: '多语言',
63+
returnToTopLabel: '回到顶部',
64+
sidebarMenuLabel: '菜单',
65+
darkModeSwitchLabel: '主题',
66+
lightModeSwitchTitle: '切换到浅色模式',
67+
darkModeSwitchTitle: '切换到深色模式',
68+
lastUpdated: {
69+
text: '上次更新于',
70+
formatOptions: {
71+
dateStyle: 'short',
72+
timeStyle: 'short',
73+
hour12: false,
74+
timeZone: 'Asia/Shanghai'
75+
}
76+
}
77+
}
78+
},
79+
en: {
80+
label: 'English',
81+
lang: 'en-US',
82+
link: '/en/',
83+
themeConfig: {
84+
nav: [
85+
{
86+
text: 'Guide',
87+
items: [{ items: enGuides }],
88+
},
89+
],
90+
sidebar: {
91+
'/en/': [
92+
{
93+
text: 'Guide',
94+
items: enGuides,
95+
},
96+
],
97+
},
98+
editLink: {
99+
pattern: 'https://github.com/cjbind/cjbind-docs/edit/master/:path',
100+
text: 'Edit this page on GitHub',
101+
},
102+
footer: {
103+
message: 'Released under the MIT License',
104+
copyright: `Copyright © 2024 - ${new Date().getFullYear()} Zxilly`,
105+
},
106+
docFooter: {
107+
prev: 'Previous',
108+
next: 'Next',
109+
},
110+
outline: {
111+
label: 'Table of Contents',
112+
level: 'deep'
113+
},
114+
lastUpdated: {
115+
text: 'Last updated',
116+
formatOptions: {
117+
dateStyle: 'short',
118+
timeStyle: 'short',
119+
}
120+
}
121+
}
122+
}
123+
},
124+
19125
markdown: {
20126
theme: {
21127
light: 'vitesse-light',
@@ -30,96 +136,57 @@ export default defineConfig({
30136
dangerLabel: '危险',
31137
infoLabel: '信息',
32138
detailsLabel: '详细信息'
33-
}
34-
},
35-
vite: {
36-
plugins: [llmstxt({
37-
domain: 'https://cjbind.zxilly.dev',
38-
description: 'cjbind 是一个自动生成仓颉到 C 库的 FFI 绑定代码的工具',
39-
})]
139+
},
40140
},
141+
41142
themeConfig: {
42143
siteTitle: 'cjbind',
43-
nav: [
44-
{
45-
text: '指南',
46-
items: [
47-
{
48-
items: GUIDES,
49-
},
50-
],
51-
},
144+
socialLinks: [
145+
{ icon: 'github', link: 'https://github.com/cjbind/cjbind' },
52146
],
53-
54-
sidebar: {
55-
'/': [
56-
{
57-
text: '指南',
58-
items: GUIDES,
59-
},
60-
],
61-
},
62-
63-
editLink: {
64-
pattern: 'https://github.com/cjbind/cjbind-docs/edit/master/:path',
65-
text: '在 GitHub 上编辑本页',
66-
},
67147
search: {
68148
provider: 'local',
69149
options: {
70-
translations: {
71-
button: {
72-
buttonText: '搜索文档',
73-
buttonAriaLabel: '搜索文档',
150+
locales: {
151+
root: {
152+
translations: {
153+
button: {
154+
buttonText: '搜索文档',
155+
buttonAriaLabel: '搜索文档',
156+
},
157+
modal: {
158+
noResultsText: '无法找到相关结果',
159+
resetButtonTitle: '清除查询条件',
160+
footer: {
161+
selectText: '选择',
162+
navigateText: '切换',
163+
closeText: '关闭',
164+
},
165+
},
166+
},
74167
},
75-
modal: {
76-
noResultsText: '无法找到相关结果',
77-
resetButtonTitle: '清除查询条件',
78-
footer: {
79-
selectText: '选择',
80-
navigateText: '切换',
81-
closeText: '关闭',
168+
en: {
169+
translations: {
170+
button: {
171+
buttonText: 'Search',
172+
buttonAriaLabel: 'Search',
173+
},
174+
modal: {
175+
noResultsText: 'No results found',
176+
resetButtonTitle: 'Reset search',
177+
footer: {
178+
selectText: 'Select',
179+
navigateText: 'Navigate',
180+
closeText: 'Close',
181+
},
182+
},
82183
},
83184
},
84185
},
85186
},
86187
},
87-
88-
socialLinks: [
89-
{ icon: 'github', link: 'https://github.com/cjbind/cjbind' },
90-
],
91-
92-
footer: {
93-
message: '以 MIT 许可证发布',
94-
copyright: `版权所有 © 2024 - ${new Date().getFullYear()} Zxilly`,
95-
},
96-
97-
docFooter: {
98-
prev: '上一页',
99-
next: '下一页',
100-
},
101-
102-
outline: {
103-
label: '目录',
104-
level: 'deep'
105-
},
106-
107-
langMenuLabel: '多语言',
108-
returnToTopLabel: '回到顶部',
109-
sidebarMenuLabel: '菜单',
110-
darkModeSwitchLabel: '主题',
111-
lightModeSwitchTitle: '切换到浅色模式',
112-
darkModeSwitchTitle: '切换到深色模式',
113-
lastUpdated: {
114-
text: '上次更新于',
115-
formatOptions: {
116-
dateStyle: 'short',
117-
timeStyle: 'short',
118-
hour12: false,
119-
timeZone: 'Asia/Shanghai'
120-
}
121-
}
122188
},
189+
123190
head: [
124191
[
125192
'script',

.vitepress/theme/index.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import DefaultTheme from 'vitepress/theme'
2+
import type { EnhanceAppContext } from 'vitepress'
3+
import { onMounted } from 'vue'
4+
5+
function handleLocaleRedirect(router: EnhanceAppContext['router']) {
6+
const hasVisited = localStorage.getItem('locale-redirect')
7+
if (hasVisited) return
8+
9+
const currentPath = window.location.pathname
10+
11+
if (currentPath.startsWith('/en/')) {
12+
localStorage.setItem('locale-redirect', 'true')
13+
return
14+
}
15+
16+
const browserLang = navigator.language || navigator.languages?.[0]
17+
18+
if (!browserLang || !browserLang.toLowerCase().startsWith('zh')) {
19+
localStorage.setItem('locale-redirect', 'true')
20+
const newPath = currentPath === '/' ? '/en/' : `/en${currentPath}`
21+
router.go(newPath)
22+
} else {
23+
localStorage.setItem('locale-redirect', 'true')
24+
}
25+
}
26+
27+
export default {
28+
extends: DefaultTheme,
29+
enhanceApp({ router }: EnhanceAppContext) {
30+
if (typeof window === 'undefined') return
31+
32+
onMounted(() => {
33+
handleLocaleRedirect(router)
34+
})
35+
}
36+
}

en/guide/command_line.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Command Line Usage
2+
3+
If you have installed `cjbind` according to the instructions in [Installation](/en/guide/install) and can view the version number using the `cjbind --version` command, you can use the `cjbind` command to generate FFI binding code.
4+
5+
The `cjbind` command takes a C header file path as input and optionally specifies an output file path for the generated bindings. If no output file path is provided, the binding code will be output to `stdout`.
6+
7+
If we want to generate Cangjie FFI bindings from a C header file named `library.h` and place them in a `cjbind_ffi.cj` file, we can invoke `cjbind` like this:
8+
9+
```bash
10+
$ cjbind -o cjbind_ffi.cj library.h
11+
```
12+
13+
To view more detailed help information, pass the `--help` argument:
14+
15+
```text
16+
$ cjbind --help
17+
Automatically generate FFI bindings from C libraries to Cangjie.
18+
19+
Usage: cjbind <OPTIONS> <HEADER> -- <CLANG_ARGS>
20+
21+
Arguments:
22+
<HEADER> C header file path
23+
[CLANG_ARGS]... Arguments that will be passed directly to clang
24+
25+
Options:
26+
--no-enum-prefix When generating enums, do not use enum names as prefixes for enum values
27+
--no-detect-include-path Disable automatic include path detection
28+
--no-comment Do not attempt to generate comments in the code
29+
--no-layout-test Do not generate layout test code
30+
--builtins Generate bindings for builtin definitions like __builtin_va_list
31+
--make-func-wrapper Generate foreign function wrappers to allow calls from outside the package
32+
--func-wrapper-suffix <SUFFIX> Suffix used when generating function wrappers, defaults to _cjbindwrapper
33+
--auto-cstring Convert char* to CString instead of CPointer<UInt8>
34+
--array-pointers-in-args Convert arrays T arr[size] to VArray<T, $size> instead of CPointer<T>
35+
--make-cjstring Convert C strings to Cangjie String instead of VArray<UInt8>, which may cause binary representation inconsistency
36+
-o, --output <FILE> Output the generated bindings to a file
37+
-p, --package <PACKAGE> Package name in the generated bindings
38+
-v, --version Display version number and exit
39+
-h, --help Display help information
40+
```

0 commit comments

Comments
 (0)