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

zh-cn: translate URL.canParse() static method #22215

Merged
merged 5 commits into from
Jul 10, 2024
Merged

Conversation

JinMokai
Copy link
Contributor

@JinMokai JinMokai commented Jul 7, 2024

Description

Translate the canParse_static method page in the url page

Motivation

Do something open source that makes sense, just this

@JinMokai JinMokai requested a review from a team as a code owner July 7, 2024 03:04
@JinMokai JinMokai requested review from jasonren0403 and removed request for a team July 7, 2024 03:04
@github-actions github-actions bot added the l10n-zh Issues related to Chinese content. label Jul 7, 2024
Copy link
Contributor

github-actions bot commented Jul 7, 2024

Preview URLs

Flaws (2)

URL: /zh-CN/docs/Web/API/URL/canParse_static
Title: URL:canParse() 静态方法
Flaw count: 2

  • macros:
    • /zh-CN/docs/Glossary/stringifier does not exist but fell back to /en-US/docs/Glossary/Stringifier
  • translation_differences:
    • Differences in the important macros (3 in common of 5 possible)
External URLs (1)

URL: /zh-CN/docs/Web/API/URL/canParse_static
Title: URL:canParse() 静态方法

(comment last updated: 2024-07-10 13:06:06)

files/zh-cn/web/api/url/canparse_static/index.md Outdated Show resolved Hide resolved
files/zh-cn/web/api/url/canparse_static/index.md Outdated Show resolved Hide resolved
Comment on lines 30 to 31
> **备注:** `url` 和 `base` 参数将根据你传递的任何值进行字符串化,就像其他接受字符串的 Web API 一样。
> 特别是,你可以使用一个现有的 {{domxref("URL")}} 对象作为任一参数,它将被字符串化为该对象的 {{domxref("URL.href", "href")}} 属性。
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
> **备注:** `url``base` 参数将根据你传递的任何值进行字符串化,就像其他接受字符串的 Web API 一样。
> 特别是,你可以使用一个现有的 {{domxref("URL")}} 对象作为任一参数,它将被字符串化为该对象的 {{domxref("URL.href", "href")}} 属性。
> **备注:** `url``base` 参数将根据你传递的任何值进行字符串化,就像其他接受字符串的 Web API 一样。特别是,你可以使用一个现有的 {{domxref("URL")}} 对象作为任一参数,它将被字符串化为该对象的 {{domxref("URL.href", "href")}} 属性。
Comment on lines 22 to 28
- `url`
- : 字符串或其他任何带有 {{Glossary("stringifier")}} 的对象(例如,包括 {{htmlelement("a")}} 或 {{htmlelement("area")}} 元素),表示绝对或相对地址。
如果 `url` 是相对地址,则 `base` 为必填项,并将用作基本地址。
如果 `url` 是绝对地址,给定的 `base` 将被忽略。
- `base` {{optional_inline}}
- : 字符串,表示在 `url` 是相对 URL 的情况下使用的基本地址。
如果未指定,则默认为 `undefined`。
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- `url`
- : 字符串或其他任何带有 {{Glossary("stringifier")}} 的对象(例如,包括 {{htmlelement("a")}} 或 {{htmlelement("area")}} 元素),表示绝对或相对地址。
如果 `url` 是相对地址,则 `base` 为必填项,并将用作基本地址。
如果 `url` 是绝对地址,给定的 `base` 将被忽略。
- `base` {{optional_inline}}
- : 字符串,表示在 `url` 是相对 URL 的情况下使用的基本地址。
如果未指定,则默认为 `undefined`。
- `url`
- : 字符串或其他任何带有 {{Glossary("stringifier")}} 的对象(例如,包括 {{htmlelement("a")}} 或 {{htmlelement("area")}} 元素),表示绝对或相对地址。如果 `url` 是相对地址,则 `base` 为必填项,并将用作基本地址。如果 `url` 是绝对地址,给定的 `base` 将被忽略。
- `base` {{optional_inline}}
- : 字符串,表示在 `url` 是相对 URL 的情况下使用的基本地址。如果未指定,则默认为 `undefined`

段落不换行

Comment on lines 54 to 56
接下来,我们使用 `URL` 中的 `canParse` 条件检查是否支持 `URL.canParse()` 方法。
如果支持该方法,我们会记录检查绝对地址、无基本地址的相对地址和有效基本地址的相对地址的结果。
我们还记录了不支持 `URL.canParse()` 的情况。
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
接下来,我们使用 `URL` 中的 `canParse` 条件检查是否支持 `URL.canParse()` 方法。
如果支持该方法,我们会记录检查绝对地址、无基本地址的相对地址和有效基本地址的相对地址的结果。
我们还记录了不支持 `URL.canParse()` 的情况。
接下来,我们使用 `URL` 中的 `canParse` 条件检查是否支持 `URL.canParse()` 方法。如果支持该方法,我们会记录检查绝对地址、无基本地址的相对地址和有效基本地址的相对地址的结果。我们还记录了不支持 `URL.canParse()` 的情况。
Comment on lines 79 to 80
最后,下面的代码表明,`baseUrl` 不一定是字符串。
这里我们传递的是一个 `URL` 对象。
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
最后,下面的代码表明,`baseUrl` 不一定是字符串。
这里我们传递的是一个 `URL` 对象。
最后,下面的代码表明,`baseUrl` 不一定是字符串。这里我们传递的是一个 `URL` 对象。
Copy link
Member

@yin1999 yin1999 left a comment

Choose a reason for hiding this comment

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

title: URL:canParse() 静态方法
slug: Web/API/URL/canParse_static
l10n:
sourceCommit: 7c7a078585a36eef960de1d93d28b20691486b99
Copy link
Member

Choose a reason for hiding this comment

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

是对应文档的最后一次��交的 commit-sha

Suggested change
sourceCommit: 7c7a078585a36eef960de1d93d28b20691486b99
sourceCommit: 1145d9748b094cf9bfd42b7ea8847ce8f647f002

{{domxref("URL")}} 接口的 **`URL.canParse()`** 静态方法返回一个布尔值,表示绝对地址或与基本地址结合的相对地址是否可解析和有效。

这是在 [try...catch](/zh-CN/docs/Web/JavaScript/Reference/Statements/try...catch) 代码块中构造 `URL` 的快速而简单的替代方法。对于与 [URL() 构造函数](/zh-CN/docs/Web/API/URL/URL)返回成功的值相同,它将返回 `true`,而对于会导致构造函数抛出的错误的值,它返回 `false`。
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
这是在 [try...catch](/zh-CN/docs/Web/JavaScript/Reference/Statements/try...catch) 代码块中构造 `URL` 的快速而简单的替代方法。对于与 [URL() 构造函数](/zh-CN/docs/Web/API/URL/URL)返回成功的值相同,它将返回 `true`,而对于会导致构造函数抛出的错误的值,它返回 `false`
这是在 [try...catch](/zh-CN/docs/Web/JavaScript/Reference/Statements/try...catch) 代码块中构造 `URL` 的快速而简单的替代方法。对于会��得 [`URL()` 构造函数](/zh-CN/docs/Web/API/URL/URL)成功的相同值,它将返回 `true`,而对于会导致构造函数抛出的错误的值,它返回 `false`
### 参数

- `url`
- : 字符串或其他任何带有 {{Glossary("stringifier")}} 的对象(例如,包括 {{htmlelement("a")}} 或 {{htmlelement("area")}} 元素),表示绝对或相对地址。如果 `url` 是相对地址,则 `base` 为必填项,并将用作基本地址。如果 `url` 是绝对地址,给定的 `base` 将被忽略。
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- : 字符串或其他任何带有 {{Glossary("stringifier")}} 的对象(例如,包括 {{htmlelement("a")}} 或 {{htmlelement("area")}} 元素),表示绝对或相对地址。如果 `url` 是相对地址,则 `base` 为必填项,并将用作基本地址。如果 `url` 是绝对地址,给定的 `base` 将被忽略。
- : 字符串或其他任何带有 {{Glossary("stringifier")}} 的对象(例如,包括 {{htmlelement("a")}} 或 {{htmlelement("area")}} 元素),表示绝对或相对 URL。如果 `url` 是相对 URL,则 `base` 为必填项,并将用作基本 URL。如果 `url` 是绝对 URL,给定的 `base` 将被忽略。
- `url`
- : 字符串或其他任何带有 {{Glossary("stringifier")}} 的对象(例如,包括 {{htmlelement("a")}} 或 {{htmlelement("area")}} 元素),表示绝对或相对地址。如果 `url` 是相对地址,则 `base` 为必填项,并将用作基本地址。如果 `url` 是绝对地址,给定的 `base` 将被忽略。
- `base` {{optional_inline}}
- : 字符串,表示在 `url` 是相对 URL 的情况下使用的基本地址。如果未指定,则默认为 `undefined`。
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- : 字符串,表示在 `url` 是相对 URL 的情况下使用的基本地址。如果未指定,则默认为 `undefined`
- : 字符串,表示在 `url` 是相对 URL 的情况下使用的基本 URL。如果未指定,则默认为 `undefined`

## 示例

本示例演示了如何使用 `URL.canParse()` 静态方法来处理一些不同的绝对地址和相对地址的值。
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
本示例演示了如何使用 `URL.canParse()` 静态方法来处理一些不同的绝对地址和相对地址的值
本示例演示了如何使用 `URL.canParse()` 静态方法来处理一些不同的绝对和相对 URL 的值
result = URL.canParse(url);
log(` URL.canParse("${url}"): ${result}`);

log("\nTest relative URL with valid base URL");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
log("\nTest relative URL with valid base URL");
log("\n测试具有有效基本 URL 的相对 URL");
result = URL.canParse(url, baseUrl);
log(` URL.canParse("${url}","${baseUrl}"): ${result}`);
} else {
log("URL.canParse() not supported");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
log("URL.canParse() not supported");
log("不支持 URL.canParse()");

```js
if ("canParse" in URL) {
log("\nTest relative URL with base URL supplied as a URL object");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
log("\nTest relative URL with base URL supplied as a URL object");
log("\n测试以 URL 对象为基本 URL 的相对 URL");

各项检查结果如下。

{{EmbedLiveSample('Examples', '100%', '200')}}
Copy link
Member

Choose a reason for hiding this comment

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

注意:https://github.com/mdn/translated-content/blob/main/docs/zh-cn/translation-guide.md#%E7%BF%BB%E8%AF%91%E6%A0%87%E9%A2%98%E5%92%8C-id

Suggested change
{{EmbedLiveSample('Examples', '100%', '200')}}
{{EmbedLiveSample('示例', '100%', '200')}}
## 参见

- {{domxref("URL.URL", "URL()")}}
- [`URL.canParse()` 的 polyfill](https://github.com/zloirock/core-js#url-and-urlsearchparams) 可在 [`core-js`](https://github.com/zloirock/core-js) 中使用
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- [`URL.canParse()` 的 polyfill](https://github.com/zloirock/core-js#url-and-urlsearchparams) 可在 [`core-js`](https://github.com/zloirock/core-js) 中使用
- [`core-js`](https://github.com/zloirock/core-js) 中可用的 [`URL.canParse()` 的 polyfill](https://github.com/zloirock/core-js#url-and-urlsearchparams)
Copy link
Contributor Author

@JinMokai JinMokai left a comment

Choose a reason for hiding this comment

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

Thank you so much for reviewing my code!

@JinMokai JinMokai requested a review from yin1999 July 9, 2024 11:18
Copy link
Member

@yin1999 yin1999 left a comment

Choose a reason for hiding this comment

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

Thanks @JinMokai

@yin1999 yin1999 changed the title zh-cn: Translate canParse_static page in Url Jul 10, 2024
@yin1999 yin1999 merged commit 1315b31 into mdn:main Jul 10, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
l10n-zh Issues related to Chinese content.
3 participants