wip(docs): i18n (#12681)

This commit is contained in:
Adam
2026-02-09 11:34:35 -06:00
committed by GitHub
parent f74c0339cc
commit dc53086c1e
642 changed files with 192745 additions and 509 deletions

View File

@@ -0,0 +1,369 @@
---
title: 主題
description: 選擇內建主題或定義您自己的主題。
---
使用 OpenCode您可以从多个内建主题中进行选择使用适合您的终端主题的主题或定义您自己的自定义主题。
By default, OpenCode uses our own `opencode` theme.
---
## 終端要求
為了使主題能夠正確顯示完整的調色盤,您的終端必須支援**真彩色**24 位顏色)。大多數現代終端預設支援此功能,但您可能需要啟用它:
- **检查支持**:执行 `echo $COLORTERM` - 它应该输出 `truecolor` 或 `24bit`
- **启用真彩色**在shell配置文件中设置环境变量`COLORTERM=truecolor`
- **您的终端相容性**确保终端模拟器支持24位颜色大多数现代终端如iTerm2、Alacritty、Kitty、Windows终端和最新版本的GNOME终端都支持
如果沒有真彩色支援,主題的顏色精度可能會降低或回落到最接近的 256 色近似值。
---
## 內建主題
OpenCode 带有几个内建主题。
|名稱 |描述 |
| ---------------------- | ---------------------------------------------------------------------------- |
| `system` |适应您所处的背景颜色|
| `tokyonight` | Based on the [Tokyonight](https://github.com/folke/tokyonight.nvim) theme |
| `everforest` | Based on the [Everforest](https://github.com/sainnhe/everforest) theme |
| `ayu` | Based on the [Ayu](https://github.com/ayu-theme) dark theme |
| `catppuccin` | Based on the [Catppuccin](https://github.com/catppuccin) theme |
| `catppuccin-macchiato` | Based on the [Catppuccin](https://github.com/catppuccin) theme |
| `gruvbox` | Based on the [Gruvbox](https://github.com/morhetz/gruvbox) theme |
| `kanagawa` | Based on the [Kanagawa](https://github.com/rebelot/kanagawa.nvim) theme |
| `nord` | Based on the [Nord](https://github.com/nordtheme/nord) theme |
| `matrix` | 骇客风格黑底绿主题|
| `one-dark` | Based on the [Atom One](https://github.com/Th3Whit3Wolf/one-nvim) Dark theme |
此外,我們還在不斷新增新主題。
---
## 系統主題
`system` 主题旨在自动适应您的最终方案。与使用固定颜色的传统主题不同_system_ 主题:
- **生成灰度**:根據終端的背景顏色建立自定義灰度,確保最佳對比度。
- **使用 ANSI 颜色**:使用标准 ANSI 颜色 (0-15) 进行语法突出显示和 UI 元素,尊重 Windows 的调色盘。
- **保留默认设置**:使用 `none` 作为文字和背景颜色以保持本机的外观。
系統主題適合以下使用者:
- 希望 OpenCode 与终端的外观相匹配
- 使用自定義終端配色方案
- 希望所有終端應用程式具有一致的外觀
---
## 使用主題
您可以通过使用 `/theme` 命令调出主题选择来选择主题。或者您可以在 [config](/docs/config) 中指定它。
```json title="opencode.json" {3}
{
"$schema": "https://opencode.ai/config.json",
"theme": "tokyonight"
}
```
---
## 自定義主題
OpenCode 支持灵活的基于 JSON 的主题系统,允许用户轻松创建和自定义主题。
---
### 等級制度
主題按以下順序從多個目錄載入,其中後面的目錄覆蓋前面的目錄:
1. **內建主題** - 這些主題嵌入在二進製檔案中
2. **User config directory** - Defined in `~/.config/opencode/themes/*.json` or `$XDG_CONFIG_HOME/opencode/themes/*.json`
3. **Project root directory** - Defined in the `<project-root>/.opencode/themes/*.json`
4. **Current working directory** - Defined in `./.opencode/themes/*.json`
如果多個目錄包含同名主題,則將使用優先順序較高的目錄中的主題。
---
### 建立主題
要创建自定义主题,请在主题目录中创建 JSON 档案。
對於使用者範圍的主題:
```bash no-frame
mkdir -p ~/.config/opencode/themes
vim ~/.config/opencode/themes/my-theme.json
```
以及針對特定專案的主題。
```bash no-frame
mkdir -p .opencode/themes
vim .opencode/themes/my-theme.json
```
---
### JSON 格式
主题使用灵活的 JSON 格式,支持:
- **十六进位制造颜色** `"#ffffff"`
- **ANSI 颜色** `3` (0-255)
- **颜色参考** `"primary"` 或自定义定义
- **深色/light 变体** `{"dark": "#000", "light": "#fff"}`
- **无颜色** `"none"` - 使用终端的默认颜色或透明
---
### 顏色定義
`defs` 部分是可选的,它允许您定义可在主题中引用的可重用颜色。
---
### 終端預設值
特殊值 `"none"` 可用于任何颜色以继承默认的默认颜色。这对于建立与终端方案无缝的融合主题特别有用:
- `"text": "none"` - 使用遥控器的预设前景色
- `"background": "none"` - 使用桌面的背景颜色
---
### 例子
以下是自定義主題的示例:
```json title="my-theme.json"
{
"$schema": "https://opencode.ai/theme.json",
"defs": {
"nord0": "#2E3440",
"nord1": "#3B4252",
"nord2": "#434C5E",
"nord3": "#4C566A",
"nord4": "#D8DEE9",
"nord5": "#E5E9F0",
"nord6": "#ECEFF4",
"nord7": "#8FBCBB",
"nord8": "#88C0D0",
"nord9": "#81A1C1",
"nord10": "#5E81AC",
"nord11": "#BF616A",
"nord12": "#D08770",
"nord13": "#EBCB8B",
"nord14": "#A3BE8C",
"nord15": "#B48EAD"
},
"theme": {
"primary": {
"dark": "nord8",
"light": "nord10"
},
"secondary": {
"dark": "nord9",
"light": "nord9"
},
"accent": {
"dark": "nord7",
"light": "nord7"
},
"error": {
"dark": "nord11",
"light": "nord11"
},
"warning": {
"dark": "nord12",
"light": "nord12"
},
"success": {
"dark": "nord14",
"light": "nord14"
},
"info": {
"dark": "nord8",
"light": "nord10"
},
"text": {
"dark": "nord4",
"light": "nord0"
},
"textMuted": {
"dark": "nord3",
"light": "nord1"
},
"background": {
"dark": "nord0",
"light": "nord6"
},
"backgroundPanel": {
"dark": "nord1",
"light": "nord5"
},
"backgroundElement": {
"dark": "nord1",
"light": "nord4"
},
"border": {
"dark": "nord2",
"light": "nord3"
},
"borderActive": {
"dark": "nord3",
"light": "nord2"
},
"borderSubtle": {
"dark": "nord2",
"light": "nord3"
},
"diffAdded": {
"dark": "nord14",
"light": "nord14"
},
"diffRemoved": {
"dark": "nord11",
"light": "nord11"
},
"diffContext": {
"dark": "nord3",
"light": "nord3"
},
"diffHunkHeader": {
"dark": "nord3",
"light": "nord3"
},
"diffHighlightAdded": {
"dark": "nord14",
"light": "nord14"
},
"diffHighlightRemoved": {
"dark": "nord11",
"light": "nord11"
},
"diffAddedBg": {
"dark": "#3B4252",
"light": "#E5E9F0"
},
"diffRemovedBg": {
"dark": "#3B4252",
"light": "#E5E9F0"
},
"diffContextBg": {
"dark": "nord1",
"light": "nord5"
},
"diffLineNumber": {
"dark": "nord2",
"light": "nord4"
},
"diffAddedLineNumberBg": {
"dark": "#3B4252",
"light": "#E5E9F0"
},
"diffRemovedLineNumberBg": {
"dark": "#3B4252",
"light": "#E5E9F0"
},
"markdownText": {
"dark": "nord4",
"light": "nord0"
},
"markdownHeading": {
"dark": "nord8",
"light": "nord10"
},
"markdownLink": {
"dark": "nord9",
"light": "nord9"
},
"markdownLinkText": {
"dark": "nord7",
"light": "nord7"
},
"markdownCode": {
"dark": "nord14",
"light": "nord14"
},
"markdownBlockQuote": {
"dark": "nord3",
"light": "nord3"
},
"markdownEmph": {
"dark": "nord12",
"light": "nord12"
},
"markdownStrong": {
"dark": "nord13",
"light": "nord13"
},
"markdownHorizontalRule": {
"dark": "nord3",
"light": "nord3"
},
"markdownListItem": {
"dark": "nord8",
"light": "nord10"
},
"markdownListEnumeration": {
"dark": "nord7",
"light": "nord7"
},
"markdownImage": {
"dark": "nord9",
"light": "nord9"
},
"markdownImageText": {
"dark": "nord7",
"light": "nord7"
},
"markdownCodeBlock": {
"dark": "nord4",
"light": "nord0"
},
"syntaxComment": {
"dark": "nord3",
"light": "nord3"
},
"syntaxKeyword": {
"dark": "nord9",
"light": "nord9"
},
"syntaxFunction": {
"dark": "nord8",
"light": "nord8"
},
"syntaxVariable": {
"dark": "nord7",
"light": "nord7"
},
"syntaxString": {
"dark": "nord14",
"light": "nord14"
},
"syntaxNumber": {
"dark": "nord15",
"light": "nord15"
},
"syntaxType": {
"dark": "nord7",
"light": "nord7"
},
"syntaxOperator": {
"dark": "nord9",
"light": "nord9"
},
"syntaxPunctuation": {
"dark": "nord4",
"light": "nord0"
}
}
}
```