Files
mintlify__docs/zh/components/code-groups.mdx
Ethan Palm 10c2294f43 fix: translation lag 3-18-26 (#4670)
* Sync es/fr/zh translations: fix broken settings links and add Data attributes section

- Update 30 broken internal links from old `organize/settings#param-*` format
  to new settings subpages (settings-api, settings-appearance, settings-seo,
  settings-structure) across es/, fr/, zh/ directories
- Fix broken link in organize/pages.mdx (all 3 langs): settings#param-metadata
  → settings-seo#metadata
- Add translated "Data attributes" subsection (data-active selectors for
  SidebarGroup, SidebarNavItem, TableOfContentsItem) to custom-scripts.mdx
  in es/, fr/, zh/

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Add navigation language subsections to zh/organize/settings-reference.mdx

Add navigation.global.languages and navigation.languages entries with current
supported language codes (including fr-CA, hu, uk) that were missing from the
zh translation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 15:23:34 -07:00

103 lines
2.5 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "代码分组"
description: "在带有标签页的界面中展示多个代码示例,以便比较不同语言的实现。"
keywords: ["code groups", "tabbed code", "multi-language examples", "CodeGroup"]
---
使用 `CodeGroup` 组件在带有标签页的界面中展示多个代码块,便于用户比较不同编程语言的实现,或查看完成同一任务的替代方案。
<CodeGroup>
```javascript helloWorld.js
console.log("Hello World");
```
```python hello_world.py
print('Hello World!')
```
```java HelloWorld.java
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
```
</CodeGroup>
代码分组将从你的 `docs.json` 文件继承全局样式。可通过 `styling.codeblocks` 自定义主题。配置选项参见 [Settings](/zh/organize/settings-appearance#styling)。
当标签相同时,同一页面上的代码分组会与其他代码分组以及 [Tabs](/zh/components/tabs) 自动同步。当你在某个代码分组中选择一种语言时,所有具有相同标签的 Tabs 和代码分组都会更新为显示相同的语言。
<div id="creating-code-groups">
## 创建代码组
</div>
要创建代码组,请使用 `<CodeGroup>` 标签包裹多个代码块。每个代码块必须包含一个 title,其值将作为标签页的标签。
````mdx
<CodeGroup>
```javascript helloWorld.js
console.log("Hello World");
```
```python hello_world.py
print('Hello World!')
```
```java HelloWorld.java
class HelloWorld {
public static void main(String[] args) {
System.out.println("你好,世界!");
}
}
```
</CodeGroup>
````
<div id="language-dropdown">
## 语言下拉菜单
</div>
你可以通过使用 `dropdown` 属性,将 CodeGroup 中的选项卡替换为下拉菜单,以在不同语言之间切换。
<CodeGroup dropdown>
```javascript helloWorld.js
console.log("Hello World");
```
```python hello_world.py
print('Hello World!')
```
```java HelloWorld.java
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
```
</CodeGroup>
````mdx highlight=1
<CodeGroup dropdown>
```javascript helloWorld.js
console.log("你好世界");
```
```python hello_world.py
print('你好世界!')
```
```java HelloWorld.java
class HelloWorld {
public static void main(String[] args) {
System.out.println("你好,世界!");
}
}
```
</CodeGroup>
````