-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
docs: api.md #50
docs: api.md #50
Conversation
认领 api.md
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/mobx-docs-cn/zh-mobx-js-org/6U23yCULsMNQsydNfaVNMY5GZiui |
翻译完毕 @iChenLei |
感谢Neo42同学的翻译工作
|
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.
以上是一些建议,望斟酌。
|
||
_Making things observable._ | ||
_把事物转化成 observable。_ |
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.
这个词比较难处理。
如果从词典中找的话,英文的解释一般都是 “that can be noticed or seen”,跟你的译法是一致的。还有一种物理学上的 “observable” 可观察量(不过好像又跟在这里的含义不一样)。
观察者模式里的 observable 跟这里比较接近。wiki 上解释观察者模式时并没有解释什么是 observable,只在代码示例里写了几种语言中 observable 的用法。我翻了几本设计模式的教材,它们在讲观察者模式的时候都不会把 observable 按词典解释翻译,一般都是保留原文(Head First 设计模式、四人帮的设计模式教材),尤其是在讲到代码的时候(比如说 Java 的内置 observable)。可以类比 generator、promise 和 async/await 理解,如果翻译出来的话,大家写代码的时候理解起来就可能不太直接。
咱们还可以参考 rxjs 的官方中文文档,他们在开头给了一个“(可观察对象)”的注解,其他地方基本上都保留了原文。
当然我也不能说“可观察的”翻译得不对。最后可能还是约定习惯的问题。可以等咱们的翻译进度走到可以考虑规范的时候再商量商量。
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.
嗯,确实,mobx里这个observable感觉是框架用这个单词来描述的一个概念。其实作用比较接近监听、被监听。但是监听明显又不是这个单词,这个还真是需要所有地方统一这个概念,如果文档对这一概念不统一,怕是看各个文档会出现理解偏差
|
||
Clones an object and makes it observable. Source can be a plain object, array, Map or Set. By default, `observable` is applied recursively. If one of the encountered values is an object or array, that value will be passed through `observable` as well. | ||
克隆一个对象并把它转化成 observable。`source` 可以是一个普通的对象、数组、Map 或 Set。默认情况下,`observable` 会递归执行。如果遇到的值中有一个是对象或数组,那么该值也会被传入 `observable`。 |
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.
“source
可以是一个普通的对象、数组、Map 或 Set。” 改为 "来源可以是 plain object, array,Map或者Set"
感觉plain object这些不翻好一点。 @Neo42 请斟酌。
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.
这里用 source
也是因为可以直接对应上面的代码用法注解,方便理解。如果翻译成“来源”的话,跟“克隆”搭配来看有点不符合中文习惯:“克隆的来源”。
顺便一句,说实话,“Source ...” 这句话的英文原文的语法出错了,少了一个冠词 the。不过如果这句话出现在口语中就不用纠结这个了。
可以具体说一下建议不翻译 plain 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.
source 我这里是想翻的更容易明白点,并没有一定要依照单词本身的意思。只是从前一句,感觉比较符合汉语理解,把这一句作为前一句的补充。
plain object 好像有的翻译是纯对象,纯对象是object.create(null)创建的,let obj = {}创建的是普通对象。其实这2个是不一样的。而且后面Map、Set也没有翻译,所以就想着都不翻译。
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.
那把 source
改成“源对象”可不可以?中文读起来比较顺口
plain object 这里可以用 Mobx 内置的 isPlainObject
方法测试一下:
const plainObjectString = Object.toString()
function isObject(value: any): value is Object {
return value !== null && typeof value === "object"
}
function isPlainObject(value) {
if (!isObject(value)) return false
const proto = Object.getPrototypeOf(value)
if (proto == null) return true
return proto.constructor?.toString() === plainObjectString
}
isPlainObject({}); // true
isPlainObject(Object.create(null)) // true
isPlainObject(new Object()) // true
isPlainObject([]); // false
isPlainObject(new Array()) // false
isPlainObject(new Map()); // false
isPlainObject(new Set()); // false
object.create(null)
是被判定为 plain object 的。
应该是每个工具对于 plain object 的界定不一样,像 Redux 里 Object.create(null)
就不算 plain object:
function isPlainObject(obj: any): boolean {
if (typeof obj !== 'object' || obj === null) return false
let proto = obj
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto)
}
return Object.getPrototypeOf(obj) === proto
}
isPlainObject({}); // true
isPlainObject(new Object()) // true
isPlainObject(Object.create(null)) // false
isPlainObject([]); // false
isPlainObject(new Array()) // false
isPlainObject(new Map()); // false
isPlainObject(new Set()); // false
docs/api.md
Outdated
|
||
Intercepts changes before they are applied to an observable API. Returns a disposer function that stops the interception. | ||
在一个 observable API 发生改变之前将该改变拦截。返回一个阻止拦截的处置函数。 |
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 API之前,其将发生变化。返回一个可以停止拦截的清除函数。"
请斟酌。
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.
如果说 intercepts 是主语名词,那它就是个复数名词,所以谓语动词 change 就不应该加 s,跟原文是矛盾的
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.
我感觉英文原文这里changes应该是多了个s,后面的they are应该指的就是拦截器。所以主句是 拦截器会发生改变。
before they are applied to an observable API 作为状语。按汉语习惯,把状态语句前置方便理解。
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.
那如果是原文省略了主语呢: “(This method) Intercepts changes before they are applied to an observable API.”
这样是说得通的,也符合 Intercept & Observe 的解释。
intercept
can be used to detect and modify mutations before they are applied to the observable (validating, normalizing or cancelling).
Edit: 不过我这里“该改变”用的不恰当,毕竟原文指的不是只有一个,可能需要改一下
感谢!我会尽快处理! |
@wuxyman 感谢校对!一部分已经按同学的建议改了,其余的可能还有待商榷,麻烦再看一下,谢谢~ |
@Neo42 已对有待商榷部分作出回答,望斟酌。 |
@wuxyman 已回复,望斟酌。 |
No description provided.