Skip to content
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

1335: feat:翻译完 1335 Type Casting⭐️⭐️⭐️⭐️ #1377

Open
wants to merge 1 commit into
base: swift-6-beta-translation
Choose a base branch
from

Conversation

hdmdhr
Copy link
Collaborator

@hdmdhr hdmdhr commented Aug 28, 2024

@hdmdhr hdmdhr self-assigned this Aug 28, 2024
@hdmdhr hdmdhr linked an issue Aug 28, 2024 that may be closed by this pull request
@hdmdhr hdmdhr changed the title feat:翻译完 1335 feat:翻译完 1335 Type Casting Aug 28, 2024
@yongfrank yongfrank changed the title feat:翻译完 1335 Type Casting 1335: feat:翻译完 1335 Type Casting⭐️⭐️⭐️⭐️ Sep 22, 2024
@yongfrank
Copy link

@Shinolr @brooklyn1999 有空请帮忙 Review Thx!

Specifically, it declares a `name` property of type `String`,
and an `init(name:)` initializer.
(It's assumed that all media items, including all movies and songs, will have a name.)
第一个代码片段定义了一个名为 `MediaItem` 的新基类。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“新基类”感觉有一点奇怪。“一个新的名为‘MediaItem’的基类‘或者干脆去掉”新“,我觉得更符合中文习惯。

(It's assumed that all media items, including all movies and songs, will have a name.)
第一个代码片段定义了一个名为 `MediaItem` 的新基类。
该类为数字媒体库中出现的任何类型项目提供基本功能。
具体来说,它声明了一个字符串类型的 `name` 属性和一个 `init(name:)` 初始化器。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT,“初始化器”在已有的翻译中是比较通用的说法了吗?另外String这种类型关键字的翻译约定是保留还是不保留?

The second subclass, `Song`, adds an `artist` property and initializer
on top of the base class:
下一个代码段定义了 `MediaItem` 的两个子类。
第一个子类 `Movie` 封装了电影或影片的附加信息。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里movie or film感觉没必要特意翻译出“电影或影片”,就叫电影或影片即可。

其中包含两个 `Movie` 实例和三个 `Song` 实例。
`library` 数组的类型是通过使用数组字面值初始化来推断的。
Swift 的类型检查程序能够推断出 `Movie` 和 `Song` 有一个共同的父类 `MediaItem`,
因此推断出 library 数组的类型为 `[MediaItem]`:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“从而”比“因此”好

you need to *check* their type,
or *downcast* them to a different type,
as described below.
`library` 中存储的项目在幕后仍然是 `Movie` 和 `Song` 实例。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“在幕后”显得非常字面意思,我觉得“事实上”可能更合适

Several of the `switch` statement's cases bind their matched value to
a constant of the specified type to enable its value to be printed:
`things` 数组包含两个 `Int` 值、两个 `Double` 值、一个 `String` 值、一个类型为 `(Double, Double)` 的元组、电影 “捉鬼敢死队”,
以及一个接收字符串值并返回另一个字符串值的闭包表达式。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

既然前面的String都保留了,闭包这里也保留吧

and queries the type of each item with a `switch` statement.
Several of the `switch` statement's cases bind their matched value to
a constant of the specified type to enable its value to be printed:
`things` 数组包含两个 `Int` 值、两个 `Double` 值、一个 `String` 值、一个类型为 `(Double, Double)` 的元组、电影 “捉鬼敢死队”,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不要直译“电影捉鬼敢死队”,可以是“movie实例”,名称翻不翻无所谓

以及一个接收字符串值并返回另一个字符串值的闭包表达式。


如果常量或变量的已知类型是 `Any` 或 `AnyObject`,要确定其具体类型,可以在 switch 语句的情况下使用 `is` 或 `as` 模式。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch-case中的case不应该翻译,应保留


如果常量或变量的已知类型是 `Any` 或 `AnyObject`,要确定其具体类型,可以在 switch 语句的情况下使用 `is` 或 `as` 模式。
下面的示例遍历了 `things` 数组中的项目,并使用 `switch` 语句查询了每个项目的类型。
该 `switch` 语句的一些情况将其匹配值与指定类型的常量绑定,以便打印其值:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case同上

> as shown below.
> 注意: `Any` 类型代表任何类型的值,包括可选类型。
> 如果你使用的是可选值,而预期值是 `Any` 类型,Swift 会发出警告。
> 如果您确实需要将可选值用作 `Any` 值,可以使用 `as` 操作符显式地将可选值转换为 `Any` 值,如下所示。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“您”->“你”

@Pancf Pancf self-requested a review September 28, 2024 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Under Review
Development

Successfully merging this pull request may close these issues.

LanguageGuide / type-casting.md ⭐️⭐️⭐️⭐️
3 participants