-
Notifications
You must be signed in to change notification settings - Fork 6
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
初稿: Translation for docs/core-concepts/events.md #16
base: master
Are you sure you want to change the base?
Conversation
|
||
## Overview | ||
|
||
## 概述 | ||
|
||
An event is a message sent from an event emitter to signify the occurrence of a specific action. This action can be generated by a user action (such as a tap) or by program logic (for instance, to indicate that downloading an image from a server has completed). The object that raises the event is called an **event sender** (simply **sender**) or **event raiser**. The object that consumes the event is called an **event listener** (simply **listener**) or **event handler**. |
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.
最后一句漏翻了?
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.
我的锅……分两次翻的……估计是漏了🙈
docs/core-concepts/events.md
Outdated
The NativeScript framework provides a class `Observable` that powers the process of working with events. Find more information about it in the [API Reference](http://docs.nativescript.org/api-reference/classes/_data_observable_.observable.html). Because it is one of the base classes within the NativeScript framework, almost every NativeScript object (component) has an option for dealing with events. | ||
|
||
NativeScript框架提供一个驱动事件工作流程的`Observable`类,你可以在 [API索引](http://docs.nativescript.org/api-reference/classes/_data_observable_.observable.html)中查看更多信息。鉴于它是NativeScript框架中最基础的类之一,几乎每一个NativeScript对象(或组件)都拥有处理事件的选项。 |
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.
NativeScript框架提供了一个。
"鉴于"通常用于描述某个主观决定的原因,一般后跟“我们”或“我”,而这里描述的是客观事实,建议翻译为“由于”。
docs/core-concepts/events.md
Outdated
To add an **event handler** means setting a function (method) that executes when the event is raised. | ||
|
||
增加一个 **event handler(事件处理器)** 意味着设置一个在特定事件发生时被执行的函数(或方法)。 |
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.
专有名词建议把中文放在括号外,英文放在括号中。而且一章中通常只要注释一次就够了。
docs/core-concepts/events.md
Outdated
|
||
### Example 1 (JavaScript): Adding an event handler or an event listener using the short and full syntax. | ||
|
||
### 例1(JavaScript):使用简写语法和完整语法来增加事件处理器(或者是事件监听器)。 |
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.
或者是 意思清楚的前提下简短点更好。
docs/core-concepts/events.md
Outdated
###Example 2: Hooking to a button tap event | ||
You need a code-behind file (see __Example 2__) to write the function body (the code-behind file has the same file name, but a different extension: .js or .ts depending on the language you are using). | ||
|
||
你需要一个隐藏代码页文件(参见 __例2__)来写出函数主体(该文件应当有同样的文件名,后缀名—.js或.ts—取决于于你所使用的语言)。 |
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.
code-behind 是.NET中的术语,一般翻译为“代码后置”,另外建议在括号里标注原文。
docs/core-concepts/events.md
Outdated
|
||
### Example 2: Hooking to a button tap event | ||
|
||
### 例2:挂靠(Hook)到按下按钮的事件上 |
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.
Hook 挂接
docs/core-concepts/events.md
Outdated
It is important to note that the `propertyChange` event is critical for the entire [data binding]({% slug binding %}) system. To take advantage of the data binding mechanism, all you have to do is make your business object **inherit** the `Observable` class. __Example 5__ demonstrates how to do that. | ||
|
||
###Example 5: Handle the propertyChange event via XML | ||
需要注意的是,`propertyChange`事件对于整个[数据绑定]({% slug binding %})系统都是不安全的。如果想要使用数据绑定带来的优势,你只需要让你的业务对象**继承(inherit)**自`Observable`类就可以了。__例5__ 是一个示范。 |
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.
这里critical应该没有“不安全”的意思,而是说它对于整个事件绑定系统“至关重要”。
“如果想要使用数据绑定带来的优势” 汉语语法不太对,可以译为:
“如果要取得数据绑定带来的好处”或“如果要取得数据绑定的优势”
docs/core-concepts/events.md
Outdated
The code snippet in __Example 5__ fires the `propertyChange` event when the switch checked value is changed. | ||
|
||
###Example 6: Creating a custom class and inheriting `Observable` class | ||
__例5__ 中的代码片段在switch的checked值改变时触发`propertyChange`事件。 |
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.
switch建议译为“开关控件”,以免被误解成js关键字。
docs/core-concepts/events.md
Outdated
|
||
If your business logic demands it, you may want to fire (raise or emit) a custom event on a particular action (see __Example 7__). To do that, call the `Observable.notify()` method when the action is completed. This method takes any **implementer** of the [EventData interface](http://docs.nativescript.org/api-reference/interfaces/_data_observable_.eventdata.html) as event data. It includes basic information about an event—its name as `eventName` and an instance of the event sender as `object`. | ||
|
||
你的业务逻辑可能会需要触发(引发(raise)或发出(emit))一个针对特定操作的自定义事件(参考 __例7__)。你只需要在该操作完成时调用`Observable.notify()`方法即可实现该目标。这个方法将任意[事件数据接口](http://docs.nativescript.org/api-reference/interfaces/_data_observable_.eventdata.html)的 **实现(implementer)** 作为事件的数据。它包括该事件的基本信息—作为`eventName`的事件名称(name)和作为`object`的事件发送者(event sender)的实例。 |
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.
最后一句有点不通顺,可以试试:代表事件名称的eventName
和代表事件发送者的object
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.
如果业务逻辑需要触发..., 可以在该事件结束时调用Observable.nofify()
...
docs/core-concepts/events.md
Outdated
To prevent these memory leaks, it is a good practice to remove your event listener handler before releasing the listener object. Unfortunately, sometimes you cannot determine the exact time to call the `off` or `removeEventListener` function. In such cases, use another option of the NativeScript framework: *weak events*. | ||
|
||
为了防止这种内存泄漏,在释放监听器对象之前移除事件监听处理器是个好习惯。不幸的是,有时你无法决定确切的调用`off`或者`removeEventListener`函数的时机。在这种情况下,使用NativeScript框架提供的另一种选项:*弱事件(weak events)*。 |
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.
“确切的调用off
或者removeEventListener
函数的时机”不通顺,建议改为
“调用off
或者removeEventListener
函数的合适时机”
docs/core-concepts/events.md
Outdated
A weak event, as its name suggests, creates an weak reference to the listener object, which helps you release the listener object without removing the event listener pointer. | ||
|
||
弱事件(Weak Events),顾名思义,它创建一个到监听器对象的弱引用(weak reference)。这将帮助你在不移除到事件监听器的指针时释放监听器对象。 |
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.
“这将帮助你在不移除到事件监听器的指针时释放监听器对象” 建议译为:
“它让你不必移除到事件监听器的引用也能释放这个监听器对象”
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.
或者:...,在无需移除事件监听器指针的情况下释放监听对象。
docs/core-concepts/events.md
Outdated
* [Adding an event handler](#adding-an-event-handler) | ||
|
||
[增加一个事件处理器](#adding-an-event-handler) |
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.
去掉“一个“
docs/core-concepts/events.md
Outdated
* [Removing an event listener](#removing-an-event-listener) | ||
|
||
[移除一个事件处理器](#removing-an-event-listener) |
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.
同上,去掉 “一个”
docs/core-concepts/events.md
Outdated
An event is a message sent from an event emitter to signify the occurrence of a specific action. This action can be generated by a user action (such as a tap) or by program logic (for instance, to indicate that downloading an image from a server has completed). The object that raises the event is called an **event sender** (simply **sender**) or **event raiser**. The object that consumes the event is called an **event listener** (simply **listener**) or **event handler**. | ||
|
||
事件是一个由事件发生器发出的用于表示一个特定操作的消息。这个操作可能由用户操作(比如一次触摸)或程序逻辑(比如从服务器下载的图片已经下载完毕)产生。产生事件的对象被称为**event sender(事件发送器)**(可简写为**sender(发送器)**)或者是**event raiser(事件发生器)**。 |
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.
事件是由事件发生器发出的用于表示一种特定操作的消息。这种操作..
docs/core-concepts/events.md
Outdated
An event is a message sent from an event emitter to signify the occurrence of a specific action. This action can be generated by a user action (such as a tap) or by program logic (for instance, to indicate that downloading an image from a server has completed). The object that raises the event is called an **event sender** (simply **sender**) or **event raiser**. The object that consumes the event is called an **event listener** (simply **listener**) or **event handler**. | ||
|
||
事件是一个由事件发生器发出的用于表示一个特定操作的消息。这个操作可能由用户操作(比如一次触摸)或程序逻辑(比如从服务器下载的图片已经下载完毕)产生。产生事件的对象被称为**event sender(事件发送器)**(可简写为**sender(发送器)**)或者是**event raiser(事件发生器)**。 |
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.
产生事件的对象称为**event sender(事件发送器..
去掉被。
docs/core-concepts/events.md
Outdated
## Adding an Event Handler | ||
|
||
## 增加一个事件处理器 |
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.
可以忽略an的翻译
docs/core-concepts/events.md
Outdated
To add an **event handler** means setting a function (method) that executes when the event is raised. | ||
|
||
增加一个 **event handler(事件处理器)** 意味着设置一个在特定事件发生时被执行的函数(或方法)。 |
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.
增加 事件处理器 意味着设置一个函数(或方法),在特定事件发生时执行。
docs/core-concepts/events.md
Outdated
__Example 1__ shows how to set a function that prints a "Hello World!" message in the console when a button is tapped. You can choose between the shorthand syntax and the full syntax or you can declare the event handler in XML. | ||
|
||
__例一__ 本例展示了如何设置一个当按钮被触碰时向控制台输出"Hello, World!"消息的函数。你可以选择使用简写语法(shorthand syntax)或者是完整语法(full syntax)。你也可以在XML中声明一个事件处理器。 |
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.
例一 本例展示了如何编写一个函数,在点击按钮时向控制台输出"Hello, World!"消息。可以使用简写语法(shorthand syntax)或者完整语法(full syntax),也可以在XML中声明事件处理器。
docs/core-concepts/events.md
Outdated
@@ -80,17 +129,28 @@ testButton2.addEventListener(buttonModule.Button.tapEvent, onTap, this); | |||
|
|||
Another option to set an event handler is to use an XML declaration. | |||
|
|||
###Example 1 (XML): Adding an event handler or an event listener using an XML declaration. | |||
你也可以使用XML声明的方式来设置事件处理器。 |
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.
“你”可以去掉。
docs/core-concepts/events.md
Outdated
###Example 2: Hooking to a button tap event | ||
You need a code-behind file (see __Example 2__) to write the function body (the code-behind file has the same file name, but a different extension: .js or .ts depending on the language you are using). | ||
|
||
你需要一个隐藏代码页文件(参见 __例2__)来写出函数主体(该文件应当有同样的文件名,后缀名—.js或.ts—取决于于你所使用的语言)。 |
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.
替换“你”为“这里”?
docs/core-concepts/events.md
Outdated
Usually you don't need to remove the event listener. You might need to do it when you want to receive the event just once or to free up resources. In such cases, you can apply the methods in __Example 3__. | ||
|
||
一般来讲你不需要移除事件监听器。如果你希望只收到该事件一次,或者是想要释放占用的资源,你可能需要移除事件监听器。在这些情况下,你可以应用 __例3__ 中提供的方法。 |
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.
人称“你”可以去掉。“收到” ->监听?
docs/core-concepts/events.md
Outdated
__Example 3__ uses the shorthand and full syntax to remove all listeners for the tap event of the testButton instance. If more than one object are listening for events, you can set a second parameter with the name of the callback function. This way only the referenced event listener is removed. When multiple event listeners with different `this` arguments are available, a third optional parameter is used. | ||
|
||
###Example 3: Removing a button tap event listener | ||
__例三__ 使用简写语法和完整语法来移除所有监听testButton实例的触碰(tap)事件的事件监听器。如果有不止一个对象正在监听事件,你可以将第二个参数指定为特定回调函数的名称(name)。使用这种方法,只有所引用的特定事件监听器会被移除。如果你需要设置多个具有不同`this`参数的事件监听器,你可以使用可选的第三个参数。 |
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.
不止一个 -> 多个
去掉人称"你"
docs/core-concepts/events.md
Outdated
|
||
### Example 3: Removing a button tap event listener | ||
|
||
### 例3:移除一个监听触碰按钮事件的事件监听器 |
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.
删除"一个"
docs/core-concepts/events.md
Outdated
|
||
### Example 8: Creating a weak event and handling a property change event | ||
|
||
### 例8:创造一个弱事件并处理一个属性改变(property change)事件 |
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.
去掉一个
docs/core-concepts/events.md
Outdated
@@ -292,16 +424,22 @@ var handlePropertyChange = function () { | |||
var weakEL = weakEventListenerModule.WeakEventListener; | |||
var weakEventListenerOptions: weakEventListenerModule.WeakEventListenerOptions = { | |||
// create a weak reference to the event listener object | |||
// 创建一个到事件监听器对象的弱引用 |
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.
// 新建一个弱引用变量,指向事件监听对象。
docs/core-concepts/events.md
Outdated
targetWeakRef: new WeakRef(this), | ||
// create a weak reference to the event sender object | ||
// 创建一个到事件发送器对象的弱引用 |
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.
同上,考虑重述。
docs/core-concepts/events.md
Outdated
### Removing a Weak Event Listener | ||
|
||
### 移除一个弱事件监听器 |
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.
删除一个
docs/core-concepts/events.md
Outdated
handlerContext: testButton | ||
} | ||
weakEL.addWeakEventListener(this.weakEventListenerOptions); | ||
``` | ||
|
||
__Example 8__ shows how to attach a weak event listener to an observable object instance. A closer look at the `handlePropertyChange` function shows that `text` property of the `this` object is changed when the `propertyChange` event is raised (via the button tap event). The function demonstrates how to use the `handlerContext` property—its value is taken as an argument to `this` inside the event handler function. | ||
|
||
__例8__ 展示了如何将一个弱事件监听器附着到一个可观测对象(observable object)的实例。查看`handlePropertyChange`函数,发现它的`this`对象的`text`属性在`propertyChange`事件(通过按钮触摸事件)引发时被改变了。该函数示范了如何使用`handlerContext`属性—它的值在事件处理器函数中被用作`this`参数。 |
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.
细看handlePropertyChange
函数,它的...
好的我全部看完了,明天抽空修改 |
刚刚全修改完了,已经Push到fork的master上了,应该就可以了吧 主要有两点疑惑:
麻烦菊苣帮忙看一下(x |
怀疑是“消费”的笔误。 |
可以改成数据中,在技术文档中使用代词有时候会增加思考成本,所以如果不是显得过于啰嗦,就少要用代词。 |
@asnowwolf translation updated |
No description provided.