i18n - docs translations (#20366)

Created by Github action

Co-authored-by: github-actions <github-actions@twenty.com>
This commit is contained in:
github-actions[bot]
2026-05-07 18:53:27 +02:00
committed by GitHub
parent 24e64350ee
commit 95bc8aea28
175 changed files with 5164 additions and 5007 deletions
@@ -1,10 +1,10 @@
---
title: Extending Objects
description: Add fields to standard Twenty objects (Person, Company, …) or to objects from other apps using defineField.
title: 扩展对象
description: 向标准 Twenty 对象添加字段(PersonCompany 等) 或使用 defineField 向其他应用的对象添加字段。
icon: wand-magic-sparkles
---
Use `defineField()` to add a field to an object you don't own — a standard Twenty object like Person or Company, or an object shipped by another installed app. Unlike inline fields declared inside [`defineObject`](/l/zh/developers/extend/apps/data/objects), standalone fields require an `objectUniversalIdentifier` to specify which object they extend.
使用 `defineField()` 为你不拥有的对象添加字段——例如像 Person Company 这样的标准 Twenty 对象,或由其他已安装应用提供的对象。 与在 [`defineObject`](/l/zh/developers/extend/apps/data/objects) 中声明的内联字段不同,独立字段需要一个 `objectUniversalIdentifier` 来指定它们要扩展的对象。
```ts src/fields/company-loyalty-tier.field.ts
import { defineField, FieldType } from 'twenty-sdk/define';
@@ -24,9 +24,9 @@ export default defineField({
});
```
## Key points
## 关键点
* `objectUniversalIdentifier` identifies the target object. For standard Twenty objects, import the constant from `twenty-sdk`:
* `objectUniversalIdentifier` 用于标识目标对象。 对于标准 Twenty 对象,从 `twenty-sdk` 导入常量:
```ts
import { STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS } from 'twenty-sdk/define';
@@ -37,12 +37,12 @@ export default defineField({
// …
```
* When defining fields **inline inside `defineObject()`**, you do **not** need `objectUniversalIdentifier` — it's inherited from the parent object.
* 在 **`defineObject()` 内联定义字段** 时,**不需要** `objectUniversalIdentifier`——它会从父对象继承。
* `defineField()` is the only way to add fields to objects you didn't create with `defineObject()`.
* `defineField()` 是为非通过 `defineObject()` 创建的对象添加字段的唯一方式。
* File location is up to you. The convention is `src/fields/\<name>.field.ts`, but the SDK detects fields anywhere in `src/`.
* 文件位置由你决定。 约定是使用 `src/fields/\<name>.field.ts`,但 SDK 会在整个 `src/` 中检测字段。
## Adding a relation to an existing object
## 向现有对象添加关系
To add a relation field (e.g. linking your custom object to a standard `Person`), use `defineField()` with `FieldType.RELATION`. The pattern is the same as for inline relations but with `objectUniversalIdentifier` set explicitly. See [Relations](/l/zh/developers/extend/apps/data/relations) for the bidirectional pattern.
要添加关系字段(例如将你的自定义对象链接到标准 `Person`),请将 `defineField()` `FieldType.RELATION` 一起使用。 模式与内联关系相同,但需要显式设置 `objectUniversalIdentifier`。 有关双向模式,请参见[关系](/l/zh/developers/extend/apps/data/relations)
@@ -4,7 +4,7 @@ description: 使用 defineObject 声明新的记录类型——具有其自身
icon: 表格
---
Custom **objects** are new record types your app adds to a workspace — Post Card, Invoice, Subscription, anything specific to your domain. Each object declares its schema (fields, relations, default values) and a stable universal identifier that survives across syncs and deploys.
自定义**对象**是你的应用在工作区中添加的新记录类型——Post CardInvoiceSubscription,或任何特定于你业务领域的内容。 每个对象都会声明其模式(字段、关系、默认值)以及一个在多次同步和部署中保持稳定的通用标识符。
```ts src/objects/post-card.object.ts
import { defineObject, FieldType } from 'twenty-sdk/define';
@@ -74,20 +74,20 @@ export default defineObject({
});
```
## Key points
## 关键点
* `universalIdentifier` 必须在各次部署间保持唯一且稳定。
* 每个字段都需要 `name`、`type`、`label` 以及其自身稳定的 `universalIdentifier`。
* `fields` 数组是可选的——你可以定义没有自定义字段的对象。
* Inline fields defined here do **not** need an `objectUniversalIdentifier` — it's inherited from the parent object. Use [`defineField()`](/l/zh/developers/extend/apps/data/extending-objects) to add fields to objects you don't own.
* You can scaffold new objects with `yarn twenty add object`, which guides you through naming, fields, and relationships. See [Architecture → Scaffolding entities](/l/zh/developers/extend/apps/getting-started/scaffolding).
* 此处定义的内联字段**不**需要 `objectUniversalIdentifier`——它会从父对象继承。 使用[`defineField()`](/l/zh/developers/extend/apps/data/extending-objects)为你不拥有的对象添加字段。
* 你可以使用 `yarn twenty add object` 脚手架创建新对象,它会引导你完成命名、字段和关系。 参见 [Architecture → Scaffolding entities](/l/zh/developers/extend/apps/getting-started/scaffolding)
<Note>
**Base fields are added automatically.** When you define a custom object, Twenty creates standard fields like `id`, `name`, `createdAt`, `updatedAt`, `createdBy`, `updatedBy`, and `deletedAt` for you. You don't need to declare them in your `fields` array — only your custom fields. You can override a default field by declaring one with the same name, but this is rarely a good idea.
**基础字段会自动添加。** 当你定义自定义对象时,Twenty 会为你创建标准字段,例如 `id``name``createdAt``updatedAt``createdBy``updatedBy` `deletedAt`。 你无需在 `fields` 数组中声明这些字段——只需声明你的自定义字段。 你可以通过声明一个同名字段来覆盖默认字段,但这么做通常并不是一个好主意。
</Note>
## What's next
## 接下来
* **Connect this object to others** — see [Relations](/l/zh/developers/extend/apps/data/relations) for the bidirectional relation pattern.
* **Add fields to objects from other apps** — see [Extending Objects](/l/zh/developers/extend/apps/data/extending-objects) for `defineField()`.
* **Display this object in the UI** — see [Views](/l/zh/developers/extend/apps/layout/views) and [Navigation Menu Items](/l/zh/developers/extend/apps/layout/navigation-menu-items) to put it in the sidebar.
* **将此对象与其他对象关联**——关于双向关系模式,参见 [Relations](/l/zh/developers/extend/apps/data/relations)
* **为其他应用的对象添加字段**——关于 `defineField()`,参见 [Extending Objects](/l/zh/developers/extend/apps/data/extending-objects)
* **在 UI 中展示此对象**——参见 [Views](/l/zh/developers/extend/apps/layout/views) [Navigation Menu Items](/l/zh/developers/extend/apps/layout/navigation-menu-items),将其放入侧边栏。
@@ -1,10 +1,10 @@
---
title: Overview
description: Shape the data your app adds to a workspace — objects, fields, and relations.
title: 概览
description: 定义你的应用在工作区中添加的数据结构——对象、字段和关系。
icon: database
---
A Twenty app's **data layer** is the data your app *adds* to a workspace — the new record types it declares, the columns it adds to existing objects, and how those records connect to each other.
Twenty 应用的 **数据层(data layer** 是你的应用*添加*到工作区中的数据——它声明的新记录类型、它为现有对象添加的列,以及这些记录之间如何相互关联。
```text
┌──────────────────────────────────────────────────┐
@@ -23,30 +23,30 @@ A Twenty app's **data layer** is the data your app *adds* to a workspace — the
└──────────────────────────────────────────────────┘
```
## In this section
## 本节内容
<CardGroup cols={2}>
<Card title="Objects" icon="table" href="/l/zh/developers/extend/apps/data/objects">
`defineObject` — declare new record types with their own fields.
<Card title="对象" icon="表格" href="/l/zh/developers/extend/apps/data/objects">
`defineObject` —— 使用其自有字段声明新的记录类型。
</Card>
<Card title="Extending Objects" icon="wand-magic-sparkles" href="/l/zh/developers/extend/apps/data/extending-objects">
`defineField` — add fields to standard or other apps' objects.
<Card title="扩展对象" icon="wand-magic-sparkles" href="/l/zh/developers/extend/apps/data/extending-objects">
`defineField` —— 向标准对象或其他应用的对象添加字段。
</Card>
<Card title="Relations" icon="diagram-project" href="/l/zh/developers/extend/apps/data/relations">
Bidirectional `MANY_TO_ONE` / `ONE_TO_MANY` connections between objects.
<Card title="关系" icon="diagram-project" href="/l/zh/developers/extend/apps/data/relations">
对象之间的双向 `MANY_TO_ONE` / `ONE_TO_MANY` 连接。
</Card>
</CardGroup>
## Entities at a glance
## 实体一览
| Entity | Purpose | Defined with |
| ------------ | ----------------------------------------------------------------------------------------------------------------- | ----------------------------------------- |
| **Object** | A new custom record type (e.g. PostCard, Invoice) with its own fields | `defineObject()` |
| **Field** | A column on an object. Standalone fields can extend objects you didn't create (e.g. add `loyaltyTier` to Company) | `defineField()` |
| **Relation** | A bidirectional link between two objects — both sides declared as fields | `defineField()` with `FieldType.RELATION` |
| 实体 | 目的 | 定义方式 |
| ------ | ----------------------------------------------------- | ------------------------------------------- |
| **对象** | 具有自有字段的新自定义记录类型(例如 PostCardInvoice | `defineObject()` |
| **字段** | 对象上的一列。 独立字段可以扩展你未创建的对象(例如向 Company 添加 `loyaltyTier` | `defineField()` |
| **关系** | 两个对象之间的双向链接——双方都声明为字段 | 使用 `defineField()` 并指定 `FieldType.RELATION` |
The SDK detects these via AST analysis at build time, so file organization is up to you — the convention is `src/objects/` and `src/fields/`. Stable `universalIdentifier` UUIDs tie everything together across deploys.
SDK 会在构建时通过 AST 分析检测这些内容,因此文件组织方式由你决定——约定是使用 `src/objects/` `src/fields/`。 稳定的 `universalIdentifier` UUID 在不同部署之间将一切关联在一起。
<Note>
Looking for **Application Config** or **Roles & Permissions**? Those describe the app itself rather than the data it adds — they live under [Config](/l/zh/developers/extend/apps/config/overview). Looking for **Connections** (Linear, GitHub, Slack OAuth)? Those exist to be called *from* logic functions and live under [Logic](/l/zh/developers/extend/apps/logic/connections).
在找 **Application Config** **Roles & Permissions** 吗? 这些描述的是应用本身而不是它添加的数据——相关内容位于 [Config](/l/zh/developers/extend/apps/config/overview) 下。 在找 **Connections**LinearGitHubSlack OAuth)吗? 这些用于*从*逻辑函数中调用,并位于 [Logic](/l/zh/developers/extend/apps/logic/connections) 下。
</Note>
@@ -1,30 +1,30 @@
---
title: 关系
description: Connect objects together with bidirectional MANY_TO_ONE / ONE_TO_MANY relations.
description: 使用双向 MANY_TO_ONE / ONE_TO_MANY 关系将对象连接在一起。
icon: diagram-project
---
Relations connect two objects together. In Twenty, relations are always **bidirectional** — every relation has two sides, and each side is declared as a field that references the other.
关系用于将两个对象连接在一起。 在 Twenty 中,关系始终是 **双向的**——每个关系都有两侧,每一侧都作为一个字段声明,并引用另一侧。
| 关系类型 | 描述 | 是否有外键? |
| ------------- | ------------------- | --------------------- |
| `MANY_TO_ONE` | 该对象的多条记录指向目标对象的一条记录 | 是(`joinColumnName` |
| `ONE_TO_MANY` | 该对象的一条记录拥有目标对象的多条记录 | No (the inverse side) |
| 关系类型 | 描述 | 是否有外键? |
| ------------- | ------------------- | ------------------- |
| `MANY_TO_ONE` | 该对象的多条记录指向目标对象的一条记录 | 是(`joinColumnName` |
| `ONE_TO_MANY` | 该对象的一条记录拥有目标对象的多条记录 | 否(反向侧) |
## How relations work
## 关系如何工作
Every relation requires **two fields** that reference each other:
每个关系都需要两个相互引用的字段:
1. The **MANY_TO_ONE** side — lives on the object that holds the foreign key.
2. The **ONE_TO_MANY** side — lives on the object that owns the collection.
1. **MANY_TO_ONE** 侧——位于持有外键的对象上。
2. **ONE_TO_MANY** 侧——位于拥有集合的对象上。
Both fields use `FieldType.RELATION` and cross-reference each other via `relationTargetFieldMetadataUniversalIdentifier`.
两个字段都使用 `FieldType.RELATION`,并通过 `relationTargetFieldMetadataUniversalIdentifier` 相互交叉引用。
## Example: Post Card has many Recipients
## 示例:Post Card 拥有多个收件人
A `PostCard` can be sent to many `PostCardRecipient` records. Each recipient belongs to exactly one post card.
一个 `PostCard` 可以发送给多个 `PostCardRecipient` 记录。 每个收件人只隶属于一张 PostCard
**Step 1: Define the ONE_TO_MANY side on PostCard** (the "one" side):
**步骤 1:在 PostCard 上定义 ONE_TO_MANY 侧**(“一”侧):
```ts src/fields/post-card-recipients-on-post-card.field.ts
import { defineField, FieldType, RelationType } from 'twenty-sdk/define';
@@ -51,7 +51,7 @@ export default defineField({
});
```
**Step 2: Define the MANY_TO_ONE side on PostCardRecipient** (the "many" side — holds the foreign key):
**步骤 2:在 PostCardRecipient 上定义 MANY_TO_ONE 侧**(“多”侧——持有外键):
```ts src/fields/post-card-on-post-card-recipient.field.ts
import { defineField, FieldType, RelationType, OnDeleteAction } from 'twenty-sdk/define';
@@ -81,12 +81,12 @@ export default defineField({
```
<Note>
**Circular imports:** both relation fields reference each other's `universalIdentifier`. To avoid circular import issues, export your field IDs as named constants from each file and import them in the other. The build system resolves these at compile time.
\*\*循环导入:\*\*两个关系字段相互引用对方的 `universalIdentifier`。 为避免循环导入问题,请在各自文件中将字段 ID 作为具名常量导出,并在另一个文件中导入它们。 构建系统会在编译时解析这些引用。
</Note>
## Relating to standard objects
## 与标准对象建立关系
To create a relation with a built-in Twenty object (Person, Company, etc.), use `STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS`:
要与内置的 Twenty 对象(PersonCompany 等)建立关系,请使用 `STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS`
```ts src/fields/person-on-self-hosting-user.field.ts
import {
@@ -120,20 +120,20 @@ export default defineField({
});
```
## Relation field properties
## 关系字段属性
| Property | Required | Description |
| ------------------------------------------------- | ---------------- | ----------------------------------------------------------------------------------------------------- |
| `type` | Yes | Must be `FieldType.RELATION` |
| `relationTargetObjectMetadataUniversalIdentifier` | Yes | The `universalIdentifier` of the target object |
| `relationTargetFieldMetadataUniversalIdentifier` | Yes | The `universalIdentifier` of the matching field on the target object |
| `universalSettings.relationType` | Yes | `RelationType.MANY_TO_ONE` or `RelationType.ONE_TO_MANY` |
| `universalSettings.onDelete` | MANY_TO_ONE only | What happens when the referenced record is deleted: `CASCADE`, `SET_NULL`, `RESTRICT`, or `NO_ACTION` |
| `universalSettings.joinColumnName` | MANY_TO_ONE only | Database column name for the foreign key (e.g., `postCardId`) |
| 属性 | 必填 | 描述 |
| ------------------------------------------------- | ---------------- | -------------------------------------------------------------- |
| `type` | | 必须为 `FieldType.RELATION` |
| `relationTargetObjectMetadataUniversalIdentifier` | | 目标对象的 `universalIdentifier` |
| `relationTargetFieldMetadataUniversalIdentifier` | | 目标对象上匹配字段的 `universalIdentifier` |
| `universalSettings.relationType` | | `RelationType.MANY_TO_ONE` `RelationType.ONE_TO_MANY` |
| `universalSettings.onDelete` | 仅适用于 MANY_TO_ONE | 当被引用的记录被删除时的处理方式:`CASCADE``SET_NULL``RESTRICT` `NO_ACTION` |
| `universalSettings.joinColumnName` | 仅适用于 MANY_TO_ONE | 外键的数据库列名(例如,`postCardId` |
## Inline relation fields
## 内联关系字段
You can also declare a relation directly inside [`defineObject`](/l/zh/developers/extend/apps/data/objects). When inline, omit `objectUniversalIdentifier` — it's inherited from the parent object:
你也可以直接在 [`defineObject`](/l/zh/developers/extend/apps/data/objects) 中声明关系。 以内联方式声明时,省略 `objectUniversalIdentifier`——它会从父对象继承:
```ts
export default defineObject({