-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ContribDoc: i18n guidelines(zh) #15397
Open
shrinktofit
wants to merge
11
commits into
cocos:develop
Choose a base branch
from
shrinktofit:patch-2
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+113
−0
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bd4b7ea
ContribDoc: i18n guidelines
shrinktofit 6cabcb2
Update i18n-zh.md
shrinktofit 858edf4
Update i18n-zh.md
shrinktofit 43b3ee2
Update i18n-zh.md
shrinktofit 0a6a5fa
Update i18n-zh.md
shrinktofit 3c74be6
Update i18n-zh.md
shrinktofit 25aa246
Update i18n-zh.md
shrinktofit dc6b867
Update i18n-zh.md
shrinktofit 20c47e4
Update i18n-zh.md
shrinktofit 863c26d
Update i18n-zh.md
shrinktofit 973f904
Update i18n-zh.md
shrinktofit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# 国际化 | ||
|
||
本文描述在贡献引擎功能到本仓库时,如何将功能中出现的一些文本国际化。具体来说,本文描述: | ||
|
||
- 如何让一个 cc 类对象的可编辑属性的 **显示名称**、**工具提示** 有贴合当前语言环境的表现。 | ||
|
||
## 术语 | ||
|
||
- `cc 类` | ||
|
||
指那些用 `@ccclass` 装饰器装饰的类。 | ||
|
||
- `cc 类名` | ||
|
||
指传给 `@ccclass()` 的类名参数。 | ||
|
||
- `编辑器属性` | ||
|
||
指 cc 类中,那些用 `@editable`、`@visible` 等装饰器装饰的属性。这些属性会在编辑器中展示。 | ||
|
||
- `字典` | ||
|
||
每个目标语言都有一个字典文件。里面存储的是一些文本在该语言中的表示。 本仓库目前支持简体中文和英文两种语言: | ||
|
||
- [简体中文](/editor/i18n/zh/localization.js) | ||
|
||
- [英文](/editor/i18n/en/localization.js) | ||
|
||
> 该字典文件是用 JS 代码生成的。该 JS 模块导出的内容就是字典对象的内容。 | ||
|
||
## 国际化 CC 类对象的可编辑属性 | ||
|
||
假设有以下 cc 类: | ||
|
||
```ts | ||
@ccclass('cc.Animation') | ||
class Animation { | ||
@editable | ||
clips: AnimationClip[] = []; | ||
|
||
@editable | ||
defaultClip: AnimationClip | null = null; | ||
} | ||
``` | ||
|
||
为了在编辑器中多语言展示属性 `clips` 和 `defaultClip` 的显示名称或工具提示,只需在 **各个语言字典** 的 `classes.cc` 对象里面,加入以下数据: | ||
|
||
```js | ||
// 确保这一段包裹在字典的 `classes.cc` 对象中。 | ||
'Animation': { | ||
properties: { | ||
'clips': { | ||
displayName: '<属性 clips 的编辑器显示名称>', | ||
tooltip: '<属性 clips 的工具提示。>', | ||
}, | ||
'defaultClip': { | ||
displayName: '<属性 defaultClip 的编辑器显示名称>', | ||
tooltip: '<属性 defaultClip 的工具提示。>', | ||
}, | ||
}, | ||
}, | ||
``` | ||
|
||
又比如,你的 cc 类名是 `cc.physics.BoxCollidier`,那么只需在 `BoxCollidier` 外套个命名空间即可: | ||
|
||
```js | ||
// 确保这一段包裹在字典的 `classes.cc` 对象中。 | ||
'physics': { | ||
'BoxCollidier': { | ||
properties: { /* ... */ }, | ||
} | ||
}, | ||
``` | ||
|
||
### 字典继承 | ||
|
||
很多时候,类的属性来自于基类。例如: | ||
|
||
```ts | ||
@ccclass('Base') | ||
class Base { | ||
@editable | ||
baseProp = 1; | ||
} | ||
|
||
@ccclass('Sub') | ||
class Sub extends Base { | ||
@editable | ||
subProp = false; | ||
} | ||
``` | ||
pandamicro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
为了声明这种属性继承关系,子类的字典中可以通过 `__extends__` 来继承基类的字典: | ||
|
||
```js | ||
{ | ||
classes: { | ||
'base': { // 基类字典 | ||
properties: { | ||
'baseProp': { /* ... */ } | ||
}, | ||
}, | ||
|
||
'sub': { // 子类字典 | ||
properties: { | ||
__extends__: 'classes.base.properties', // 继承基类字典的所有属性。注意,这里要填入的是基类字典的 `properties` 属性的完整路径。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not convenient to add it for every sub class. |
||
'subProp': { /* ... */ } | ||
}, | ||
}, | ||
}, | ||
} | ||
``` | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the link to the actual example file in engine repo, so that user can see where it is