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

Translate "Function" and "Exception" part of library/re.po #996

Open
wants to merge 1 commit into
base: 3.13
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 87 additions & 16 deletions library/re.po
Original file line number Diff line number Diff line change
Expand Up @@ -1221,14 +1221,16 @@ msgstr ""

#: ../../library/re.rst:878
msgid "Functions"
msgstr ""
msgstr "函式"

#: ../../library/re.rst:882
msgid ""
"Compile a regular expression pattern into a :ref:`regular expression object "
"<re-objects>`, which can be used for matching using its :func:`~Pattern."
"match`, :func:`~Pattern.search` and other methods, described below."
msgstr ""
"將正規表示式模式編譯成\\ :ref:`正規表示式物件 <re-objects>`,可以使用它的 :"
"func:`~Pattern.match`、:func:`~Pattern.search` 等方法來匹配,如下所述。"

#: ../../library/re.rst:887 ../../library/re.rst:919 ../../library/re.rst:937
#: ../../library/re.rst:948 ../../library/re.rst:994 ../../library/re.rst:1028
Expand All @@ -1239,31 +1241,37 @@ msgid ""
"Values can be any of the `flags`_ variables, combined using bitwise OR (the "
"``|`` operator)."
msgstr ""
"可以透過指定 *flags* 值來修改運算式的行為,值可以是任何 `flags`_ 變數,使用位"
"元 OR(bitwise OR、``|`` 運算子)組合。"

#: ../../library/re.rst:891
msgid "The sequence ::"
msgstr ""
msgstr "順序為: ::"

#: ../../library/re.rst:893
msgid ""
"prog = re.compile(pattern)\n"
"result = prog.match(string)"
msgstr ""
"prog = re.compile(pattern)\n"
"result = prog.match(string)"

#: ../../library/re.rst:896
msgid "is equivalent to ::"
msgstr "等價於: ::"

#: ../../library/re.rst:898
msgid "result = re.match(pattern, string)"
msgstr ""
msgstr "result = re.match(pattern, string)"

#: ../../library/re.rst:900
msgid ""
"but using :func:`re.compile` and saving the resulting regular expression "
"object for reuse is more efficient when the expression will be used several "
"times in a single program."
msgstr ""
"但是當表示式在單一程式中多次使用時,使用 :func:`re.compile` 並保存產生的正規"
"表示式物件以供重複使用會更有效率。"

#: ../../library/re.rst:906
msgid ""
Expand All @@ -1272,6 +1280,8 @@ msgid ""
"that use only a few regular expressions at a time needn't worry about "
"compiling regular expressions."
msgstr ""
"傳遞給 :func:`re.compile` 之最新模式的編譯版本和模組層級匹配函式都會被快取,"
"因此一次僅使用幾個正規表示式的程式不必去擔心編譯正規表示式。"

#: ../../library/re.rst:914
msgid ""
Expand All @@ -1281,6 +1291,9 @@ msgid ""
"pattern; note that this is different from finding a zero-length match at "
"some point in the string."
msgstr ""
"掃描 *string* 以尋找正規表示式 *pattern* 產生匹配的第一個位置,並回傳對應的 :"
"class:`~re.Match`。如果字串中沒有與模式匹配的位置則回傳 ``None``;請注意,這"
"與在字串中的某個點查找零長度匹配不同。"

#: ../../library/re.rst:926
msgid ""
Expand All @@ -1289,25 +1302,34 @@ msgid ""
"``None`` if the string does not match the pattern; note that this is "
"different from a zero-length match."
msgstr ""
"如果 *string* 開頭的零個或多個字元與正規表示式 *pattern* 匹配,則回傳對應的 :"
"class:`~re.Match`。如果字串與模式不匹配,則回傳 ``None``;請注意,這與零長度"
"匹配不同。"

#: ../../library/re.rst:931
msgid ""
"Note that even in :const:`MULTILINE` mode, :func:`re.match` will only match "
"at the beginning of the string and not at the beginning of each line."
msgstr ""
"請注意,即使在 :const:`MULTILINE` 模式 (mode) 下,:func:`re.match` 只會於字串"
"的開頭匹配,而非每行的開頭。"

#: ../../library/re.rst:934
msgid ""
"If you want to locate a match anywhere in *string*, use :func:`search` "
"instead (see also :ref:`search-vs-match`)."
msgstr ""
"如果你想在 *string* 中的任何位置找到匹配項,請使用 :func:`search`\\ (另請參"
"閱 :ref:`search-vs-match`)。"

#: ../../library/re.rst:944
msgid ""
"If the whole *string* matches the regular expression *pattern*, return a "
"corresponding :class:`~re.Match`. Return ``None`` if the string does not "
"match the pattern; note that this is different from a zero-length match."
msgstr ""
"如果整個 *string* 與正規表示式 *pattern* 匹配,則回傳對應的 :class:`~re."
"Match`。如果字串與模式不匹配,則回傳 ``None``;請注意,這與零長度匹配不同。"

#: ../../library/re.rst:957
msgid ""
Expand All @@ -1317,6 +1339,9 @@ msgid ""
"*maxsplit* splits occur, and the remainder of the string is returned as the "
"final element of the list. ::"
msgstr ""
"依 *pattern* 的出現次數拆分 *string*。如果在 *pattern* 中使用捕獲括號,則模式"
"中所有群組的文字也會作為結果串列的一部分回傳。如果 *maxsplit* 非零,則最多發"
"生 *maxsplit* 次拆分,並且字串的其餘部分會作為串列的最終元素回傳。 ::"

#: ../../library/re.rst:963
msgid ""
Expand Down Expand Up @@ -1344,6 +1369,8 @@ msgid ""
"of the string, the result will start with an empty string. The same holds "
"for the end of the string::"
msgstr ""
"如果分隔符號中有捕獲群組並且它在字串的開頭匹配,則結果將以空字串開頭。這同樣"
"適用於字串的結尾: ::"

#: ../../library/re.rst:976
msgid ""
Expand All @@ -1357,13 +1384,13 @@ msgstr ""
msgid ""
"That way, separator components are always found at the same relative indices "
"within the result list."
msgstr ""
msgstr "如此一來,分隔符號元件始終可以在結果串列中的相同相對索引處找到。"

#: ../../library/re.rst:982
msgid ""
"Empty matches for the pattern split the string only when not adjacent to a "
"previous empty match."
msgstr ""
msgstr "只有當與先前的空匹配不相鄰時,模式的空匹配才會拆分字串。"

#: ../../library/re.rst:985
msgid ""
Expand All @@ -1390,21 +1417,25 @@ msgstr "新增可選的旗標引數。"
#: ../../library/re.rst:1001
msgid ""
"Added support of splitting on a pattern that could match an empty string."
msgstr ""
msgstr "新增了對可以匹配空字串之模式進行拆分的支援。"

#: ../../library/re.rst:1004
msgid ""
"Passing *maxsplit* and *flags* as positional arguments is deprecated. In "
"future Python versions they will be :ref:`keyword-only parameters <keyword-"
"only_parameter>`."
msgstr ""
"將 *maxsplit* 和 *flags* 作為位置引數傳遞的用法已被棄用。在未來的 Python 版本"
"中,它們將會是\\ :ref:`僅限關鍵字參數 <keyword-only_parameter>`。"

#: ../../library/re.rst:1012
msgid ""
"Return all non-overlapping matches of *pattern* in *string*, as a list of "
"strings or tuples. The *string* is scanned left-to-right, and matches are "
"returned in the order found. Empty matches are included in the result."
msgstr ""
"以字串或元組串列的形式回傳 *string* 中 *pattern* 的所有非重疊匹配項。從左到右"
"掃描 *string*,並按找到的順序回傳符合項目。結果中會包含空匹配項。"

#: ../../library/re.rst:1016
msgid ""
Expand All @@ -1415,10 +1446,13 @@ msgid ""
"matching the groups. Non-capturing groups do not affect the form of the "
"result."
msgstr ""
"結果取決於模式中捕獲群組的數量。如果沒有群組,則回傳與整個模式匹配的字串串"
"列。如果恰好存在一個群組,則回傳與該群組匹配的字串串列。如果存在多個群組,則"
"回傳與群組匹配的字串元組串列。非捕獲群組則不影響結果的形式。"

#: ../../library/re.rst:1032 ../../library/re.rst:1047
msgid "Non-empty matches can now start just after a previous empty match."
msgstr ""
msgstr "非空匹配現在可以剛好在前一個空匹配的後面開始。"

#: ../../library/re.rst:1038
msgid ""
Expand All @@ -1427,6 +1461,9 @@ msgid ""
"scanned left-to-right, and matches are returned in the order found. Empty "
"matches are included in the result."
msgstr ""
"回傳一個 :term:`iterator`,在 *string* 中的 RE *pattern* 的所有非重疊匹配上 "
"yield :class:`~re.Match` 物件。從左到右掃描 *string*,並按找到的順序回傳匹配"
"項目。結果中包含空匹配項。"

#: ../../library/re.rst:1053
msgid ""
Expand All @@ -1441,6 +1478,12 @@ msgid ""
"``\\6``, are replaced with the substring matched by group 6 in the pattern. "
"For example::"
msgstr ""
"回傳透過以替換 *repl* 取代 *string* 中最左邊不重疊出現的 *pattern* 所獲得的字"
"串。如果未找到該模式,則不改變 *string* 並回傳。*repl* 可以是字串或函式;如果"
"它是字串,則處理其中的任何反斜線轉義。也就是說 ``\\n`` 會被轉換為單一換行符、"
"``\\r`` 會被轉換為回車符 (carriage return) 等等。ASCII 字母的未知轉義符會被保"
"留以供將來使用並被視為錯誤。其他未知轉義符例如 ``\\&`` 會被保留。例如 "
Copy link
Collaborator

@beccalzh beccalzh Dec 22, 2024

Choose a reason for hiding this comment

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

Suggested change
"留以供將來使用並被視為錯誤。其他未知轉義符例如 ``\\&`` 會被保留。例如 "
"留以供將來使用並被視為錯誤。其他未知轉義符例如 ``\\&`` 會被單獨保留。例如 "

"``\\6`` 的反向參照將被替換為模式中第 6 組匹配的子字串。例如: ::"

#: ../../library/re.rst:1064
msgid ""
Expand All @@ -1460,6 +1503,8 @@ msgid ""
"of *pattern*. The function takes a single :class:`~re.Match` argument, and "
"returns the replacement string. For example::"
msgstr ""
"如果 *repl* 是一個函式,則 *pattern* 的每個不重疊出現之處都會呼叫它。此函式接"
"收單一 :class:`~re.Match` 引數,並回傳替換字串。例如: ::"

#: ../../library/re.rst:1073
msgid ""
Expand All @@ -1485,7 +1530,7 @@ msgstr ""

#: ../../library/re.rst:1082
msgid "The pattern may be a string or a :class:`~re.Pattern`."
msgstr ""
msgstr "此模式可以是字串或 :class:`~re.Pattern`。"

#: ../../library/re.rst:1084
msgid ""
Expand All @@ -1495,6 +1540,9 @@ msgid ""
"only when not adjacent to a previous empty match, so ``sub('x*', '-', "
"'abxd')`` returns ``'-a-b--d-'``."
msgstr ""
"可選引數 *count* 是要替換的模式出現的最大次數;*count* 必須是非負整數。如果省"
"略或為零,則所有出現的內容都將被替換。只有當與先前的空匹配不相鄰時,模式的空"
"匹配才會被替換,因此 ``sub('x*', '-', 'abxd')`` 會回傳 ``'-a-b--d -'``。"

#: ../../library/re.rst:1092
msgid ""
Expand All @@ -1508,50 +1556,67 @@ msgid ""
"backreference ``\\g<0>`` substitutes in the entire substring matched by the "
"RE."
msgstr ""
"在字串型別 *repl* 引數中,除了上述字元轉義和反向參照之外,``\\g<name>`` 將使"
"用名為 ``name`` 的群組所匹配到的子字串,如 ``(?P<name>...)`` 所定義的語法。"
"``\\g<number>`` 使用對應的群組編號;因此 ``\\g<2>`` 等價於 ``\\2``,但在諸如 "
"``\\g<2>0`` 之類的替換中並非模糊不清 (isn't ambiguous)。``\\20`` 將被直譯為對"
"群組 20 的參照,而不是對後面跟著字面字元 ``'0'`` 的群組 2 的參照。反向參照 "
"``\\g<0>`` 會取代以 RE 所匹配到的整個子字串。"
Copy link
Collaborator

Choose a reason for hiding this comment

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

想問個replacesubtitute,有需要統一分別翻成替換取代嗎?


#: ../../library/re.rst:1109 ../../library/re.rst:1387
msgid "Unmatched groups are replaced with an empty string."
msgstr ""
msgstr "不匹配的群組將被替換為空字串。"

#: ../../library/re.rst:1112
msgid ""
"Unknown escapes in *pattern* consisting of ``'\\'`` and an ASCII letter now "
"are errors."
msgstr ""
"在由 ``'\\'`` 和一個 ASCII 字母組成之 *pattern* 中的未知轉義符現在為錯誤。"

#: ../../library/re.rst:1116
msgid ""
"Unknown escapes in *repl* consisting of ``'\\'`` and an ASCII letter now are "
"errors. Empty matches for the pattern are replaced when adjacent to a "
"previous non-empty match."
msgstr ""
"由 ``'\\'`` 和一個 ASCII 字母組成之 *repl* 中的未知轉義符現在為錯誤。當與先前"
"的非空匹配相鄰時,模式的空匹配將被替換。"

#: ../../library/re.rst:1122
msgid ""
"Group *id* can only contain ASCII digits. In :class:`bytes` replacement "
"strings, group *name* can only contain bytes in the ASCII range "
"(``b'\\x00'``-``b'\\x7f'``)."
msgstr ""
"群組 *id* 只能包含 ASCII 數字。在 :class:`bytes` 替換字串中,群組 *name* 只能"
"包含 ASCII 範圍內的位元組 (``b'\\x00'``-``b'\\x7f'``)。"

#: ../../library/re.rst:1127
msgid ""
"Passing *count* and *flags* as positional arguments is deprecated. In future "
"Python versions they will be :ref:`keyword-only parameters <keyword-"
"only_parameter>`."
msgstr ""
"將 *count* 和 *flags* 作為位置引數傳遞的用法已被棄用。在未來的 Python 版本"
"中,它們將會是\\ :ref:`僅限關鍵字參數 <keyword-only_parameter>`。"

#: ../../library/re.rst:1135
msgid ""
"Perform the same operation as :func:`sub`, but return a tuple ``(new_string, "
"number_of_subs_made)``."
msgstr ""
"執行與 :func:`sub` 相同的操作,但回傳一個元組 ``(new_string, "
"number_of_subs_made)``。"

#: ../../library/re.rst:1145
msgid ""
"Escape special characters in *pattern*. This is useful if you want to match "
"an arbitrary literal string that may have regular expression metacharacters "
"in it. For example::"
msgstr ""
"對 *pattern* 中的特殊字元進行轉義。如果你想要匹配其中可能包含正規表示式元字"
"元 (metacharacter) 的任意文本字串,這會非常有用。例如: ::"

#: ../../library/re.rst:1149
msgid ""
Expand Down Expand Up @@ -1584,6 +1649,8 @@ msgid ""
"This function must not be used for the replacement string in :func:`sub` "
"and :func:`subn`, only backslashes should be escaped. For example::"
msgstr ""
"此函式不得用於 :func:`sub` 和 :func:`subn` 中的替換字串,僅應轉義反斜線。例"
"如: ::"

#: ../../library/re.rst:1163
msgid ""
Expand All @@ -1599,7 +1666,7 @@ msgstr ""

#: ../../library/re.rst:1168
msgid "The ``'_'`` character is no longer escaped."
msgstr ""
msgstr "``'_'`` 字元不再被轉義。"

#: ../../library/re.rst:1171
msgid ""
Expand All @@ -1611,7 +1678,7 @@ msgstr ""

#: ../../library/re.rst:1180
msgid "Clear the regular expression cache."
msgstr ""
msgstr "清除正規表示式快取。"

#: ../../library/re.rst:1184
msgid "Exceptions"
Expand All @@ -1626,26 +1693,29 @@ msgid ""
"pattern. The ``PatternError`` instance has the following additional "
"attributes:"
msgstr ""
"當傳遞給此處函式之一的字串不是有效的正規表示式(例如它可能包含不匹配的括號)"
"或在編譯或匹配期間發生某些其他錯誤時引發的例外。如果字串不包含模式匹配項,則"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"或在編譯或匹配期間發生某些其他錯誤時引發的例外。如果字串不包含模式匹配項,則"
"或在編譯或匹配期間發生某些其他錯誤時,將引發例外。如果字串不包含模式匹配項,則"

感覺語意上有點差別,一個描述例外發生的情形,一個是形容一種例外。

"絕不是錯誤。``PatternError`` 實例具有以下附加屬性:"

#: ../../library/re.rst:1196
msgid "The unformatted error message."
msgstr ""
msgstr "未格式化的錯誤訊息。"

#: ../../library/re.rst:1200
msgid "The regular expression pattern."
msgstr ""
msgstr "正規表示式模式。"

#: ../../library/re.rst:1204
msgid "The index in *pattern* where compilation failed (may be ``None``)."
msgstr ""
msgstr "*pattern* 中編譯失敗的索引(可能是 ``None``)。"

#: ../../library/re.rst:1208
msgid "The line corresponding to *pos* (may be ``None``)."
msgstr ""
msgstr "對應 *pos* 的列(可能是 ``None``)。"

#: ../../library/re.rst:1212
msgid "The column corresponding to *pos* (may be ``None``)."
msgstr ""
msgstr "對應 *pos* 的欄(可能是 ``None``)。"

#: ../../library/re.rst:1214
msgid "Added additional attributes."
Expand All @@ -1656,6 +1726,7 @@ msgid ""
"``PatternError`` was originally named ``error``; the latter is kept as an "
"alias for backward compatibility."
msgstr ""
"``PatternError`` 最初被命名為 ``error``;後者為了向後相容性而被保留為別名。"

#: ../../library/re.rst:1224
msgid "Regular Expression Objects"
Expand Down