diff --git a/library/cmd.po b/library/cmd.po index 238f25b3ca..276e9c779f 100644 --- a/library/cmd.po +++ b/library/cmd.po @@ -9,7 +9,7 @@ msgstr "" "Project-Id-Version: Python 3.13\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2024-09-23 07:52+0800\n" -"PO-Revision-Date: 2025-05-14 14:32+0800\n" +"PO-Revision-Date: 2025-05-19 20:25+0800\n" "Last-Translator: Dr-XYZ \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" @@ -21,7 +21,7 @@ msgstr "" #: ../../library/cmd.rst:2 msgid ":mod:`!cmd` --- Support for line-oriented command interpreters" -msgstr ":mod:`!cmd` --- 以列為導向的指令直譯器支援" +msgstr ":mod:`!cmd` --- 以列為導向的命令直譯器支援" #: ../../library/cmd.rst:9 msgid "**Source code:** :source:`Lib/cmd.py`" @@ -34,7 +34,7 @@ msgid "" "administrative tools, and prototypes that will later be wrapped in a more " "sophisticated interface." msgstr "" -":class:`Cmd` 類別提供了一個簡單的架構,用於撰寫行導向的命令直譯器。這類直譯器" +":class:`Cmd` 類別提供了一個簡單的架構,用於撰寫列導向的命令直譯器。這類直譯器" "常用於測試控制工具、管理工具以及日後將包裝於更高階介面的原型中。" #: ../../library/cmd.rst:20 @@ -45,7 +45,7 @@ msgid "" "yourself in order to inherit :class:`Cmd`'s methods and encapsulate action " "methods." msgstr "" -":class:`Cmd` 實例或其子類別實例是一種行導向的直譯器架構。通常沒有必要直接實例" +":class:`Cmd` 實例或其子類別實例是一種列導向的直譯器架構。通常沒有必要直接實例" "化 :class:`Cmd` 本身;它更適合作為你自定義的直譯器類別的父類別,讓你能繼承 :" "class:`Cmd` 的方法,並封裝動作方法。" @@ -129,10 +129,10 @@ msgid "" "`Control-F` moves the cursor to the right non-destructively, :kbd:`Control-" "B` moves the cursor to the left non-destructively, etc.)." msgstr "" -"如果已載入 :mod:`readline` 模組,輸入行將自動繼承類似 :program:`bash` 的歷史" -"紀錄編輯功能(例如 :kbd:`Control-P` 可向上捲動至上一個指令,:kbd:`Control-N` " -"向下捲動至下一個指令,:kbd:`Control-F` 非破壞性地將游標向右移動,:kbd:" -"`Control-B` 非破壞性地將游標向左移動等)。" +"如果已載入 :mod:`readline` 模組,輸入將自動繼承類似 :program:`bash` 的歷史紀" +"錄編輯功能(例如 :kbd:`Control-P` 可向上捲動至上一個命令,:kbd:`Control-N` 向" +"下捲動至下一個命令,:kbd:`Control-F` 非破壞性地將游標向右移動,:kbd:`Control-" +"B` 非破壞性地將游標向左移動等)。" #: ../../library/cmd.rst:72 msgid "An end-of-file on input is passed back as the string ``'EOF'``." @@ -147,8 +147,8 @@ msgid "" "dispatched to the method :meth:`!do_shell` (if such a method is defined)." msgstr "" "直譯器實例僅當存在 :meth:`!do_foo` 方法時,才會識別命令名稱 ``foo``。作為特殊" -"情況,以字元 ``'?'`` 開頭的行會被派發至 :meth:`do_help` 方法;另一個特殊情況" -"是,以字元 ``'!'`` 開頭的行會被派發至 :meth:`!do_shell` 方法(若該方法已定" +"情況,以字元 ``'?'`` 開頭的列會被派發至 :meth:`do_help` 方法;另一個特殊情況" +"是,以字元 ``'!'`` 開頭的列會被派發至 :meth:`!do_shell` 方法(若該方法已定" "義)。" #: ../../library/cmd.rst:84 @@ -174,7 +174,7 @@ msgstr "" "如果啟用了自動完成,命令的自動完成將會自動執行,而命令引數的自動完成則是透過" "呼叫 :meth:`!complete_foo` 方法並傳入 *text*、*line*、*begidx* 和 *endidx* 引" "數來處理。*text* 是要比對的字串前綴:所有回傳的符合項都必須以此字串開頭。" -"*line* 是目前的輸入行(前置空白會被移除),*begidx* 和 *endidx* 則分別是前綴" +"*line* 是目前的輸入列(前置空白會被移除),*begidx* 和 *endidx* 則分別是前綴" "字串的起始與結束索引,可用來根據引數所在的位置提供不同的自動完成結果。" #: ../../library/cmd.rst:99 @@ -203,24 +203,35 @@ msgid "" "command *str*, the return value of that method is returned, otherwise the " "return value from the :meth:`default` method is returned." msgstr "" +"將引數視為在回應提示字元時所輸入的內容來直譯。這個方法可以被覆寫,但通常不需" +"要這麼做;參見 :meth:`precmd` 與 :meth:`postcmd` 方法,它們提供實用的執行勾點" +"(hook)。此方法的回傳值是一個旗標,用來指出是否應該停止直譯器對命令的直譯。" +"若有對應 *str* 命令的 :meth:`!do_\\*` 方法,則會回傳該方法的回傳值;否則,回" +"傳值將來自 :meth:`default` 方法。" #: ../../library/cmd.rst:121 msgid "" "Method called when an empty line is entered in response to the prompt. If " "this method is not overridden, it repeats the last nonempty command entered." msgstr "" +"在回應提示字元時輸入空白列,會呼叫此方法。若此方法未被覆寫,則會重復上一次輸" +"入的非空命令。" #: ../../library/cmd.rst:127 msgid "" "Method called on an input line when the command prefix is not recognized. If " "this method is not overridden, it prints an error message and returns." msgstr "" +"當輸入列中的命令前綴無法辨識時,會呼叫此方法。若此方法未被覆寫,則會輸出並回" +"傳錯誤訊息。" #: ../../library/cmd.rst:133 msgid "" "Method called to complete an input line when no command-specific :meth:`!" "complete_\\*` method is available. By default, it returns an empty list." msgstr "" +"當沒有對應特定命令的 :meth:`!complete_\\*` 方法時,會呼叫此方法以完成輸入列。" +"預設會回傳空串列。" #: ../../library/cmd.rst:139 msgid "" @@ -228,6 +239,8 @@ msgid "" "column is only as wide as necessary. Columns are separated by two spaces for " "readability." msgstr "" +"此方法用來將字串串列顯示為緊湊的欄集合。每一欄的寬度僅足以容納其內容,各欄之" +"間以兩個空格分隔,以提高可讀性。" #: ../../library/cmd.rst:146 msgid "" @@ -238,6 +251,10 @@ msgid "" "the :meth:`precmd` implementation may re-write the command or simply return " "*line* unchanged." msgstr "" +"勾點方法會在直譯命令列 *line* 前執行,但會在提示字元產生並顯示後才觸發。這個" +"方法在 :class:`Cmd` 類別中為 stub,預期由子類別覆寫。回傳值會作為 :meth:" +"`onecmd` 方法所執行的命令;:meth:`precmd` 的實作可以重寫該命令,或直接回傳未" +"變更的 *line*。" #: ../../library/cmd.rst:156 msgid "" @@ -249,35 +266,43 @@ msgid "" "this method will be used as the new value for the internal flag which " "corresponds to *stop*; returning false will cause interpretation to continue." msgstr "" +"勾點方法會在命令派發完成後執行。這個方法在 :class:`Cmd` 類別中為 stub,預期由" +"子類別覆寫。*line* 是剛剛執行的命令列,而 *stop* 是一個旗標,用來指出在呼叫 :" +"meth:`postcmd` 後是否應終止執行;該值即為 :meth:`onecmd` 方法的回傳值。本方法" +"的回傳值將會更新內部的 *stop* 旗標;若回傳 false,則會繼續進行直譯。" #: ../../library/cmd.rst:167 msgid "" "Hook method executed once when :meth:`cmdloop` is called. This method is a " "stub in :class:`Cmd`; it exists to be overridden by subclasses." msgstr "" +"當 :meth:`cmdloop` 被呼叫時,此勾點方法會執行一次。這個方法在 :class:`Cmd` 類" +"別中為 stub,預期由子類別覆寫。" #: ../../library/cmd.rst:173 msgid "" "Hook method executed once when :meth:`cmdloop` is about to return. This " "method is a stub in :class:`Cmd`; it exists to be overridden by subclasses." msgstr "" +"當 :meth:`cmdloop` 即將回傳時,此勾點方法會執行一次。這個方法在 :class:`Cmd` " +"類別中為 stub,預期由子類別覆寫。" #: ../../library/cmd.rst:177 msgid "" "Instances of :class:`Cmd` subclasses have some public instance variables:" -msgstr "" +msgstr ":class:`Cmd` 子類別的實例包含一些公開的實例變數:" #: ../../library/cmd.rst:181 msgid "The prompt issued to solicit input." -msgstr "" +msgstr "用來請求輸入的提示字元。" #: ../../library/cmd.rst:186 msgid "The string of characters accepted for the command prefix." -msgstr "" +msgstr "可作為命令前綴的字元字串" #: ../../library/cmd.rst:191 msgid "The last nonempty command prefix seen." -msgstr "" +msgstr "最後一個遇到的非空命令前綴" #: ../../library/cmd.rst:196 msgid "" @@ -285,17 +310,20 @@ msgid "" "`cmdloop` when new input is needed; if it is nonempty, its elements will be " "processed in order, as if entered at the prompt." msgstr "" +"排入佇列的輸入列串列。當 :meth:`cmdloop` 需要新輸入時,會檢查 cmdqueue 串列;" +"若不為空,其元素將依序處理,就如同它們是在提示字元中輸入的一樣。" #: ../../library/cmd.rst:203 msgid "" "A string to issue as an intro or banner. May be overridden by giving the :" "meth:`cmdloop` method an argument." msgstr "" +"作為簡介或橫幅的字串。可透過為 :meth:`cmdloop` 方法提供引數來覆寫此內容。" #: ../../library/cmd.rst:209 msgid "" "The header to issue if the help output has a section for documented commands." -msgstr "" +msgstr "若說明輸出包含已記錄命令的區段,則會顯示的標頭字串。" #: ../../library/cmd.rst:214 msgid "" @@ -303,6 +331,8 @@ msgid "" "topics (that is, there are :meth:`!help_\\*` methods without corresponding :" "meth:`!do_\\*` methods)." msgstr "" +"若說明輸出包含雜項說明主題的區段(也就是存在 :meth:`!help_\\*` 方法但沒有對應" +"的 :meth:`!do_\\*` 方法),則會顯示的標頭字串。" #: ../../library/cmd.rst:221 msgid "" @@ -310,12 +340,16 @@ msgid "" "commands (that is, there are :meth:`!do_\\*` methods without corresponding :" "meth:`!help_\\*` methods)." msgstr "" +"若說明輸出包含未記錄命令的區段(也就是存在 :meth:`!do_\\*` 方法但沒有對應的 :" +"meth:`!help_\\*` 方法),則會顯示的標頭字串。" #: ../../library/cmd.rst:228 msgid "" "The character used to draw separator lines under the help-message headers. " "If empty, no ruler line is drawn. It defaults to ``'='``." msgstr "" +"用於在說明訊息的標頭下方繪製分隔線的字元。若為空,則不會繪製分隔線。預設為 " +"``'='``。" #: ../../library/cmd.rst:234 msgid "" @@ -326,22 +360,30 @@ msgid "" "the interpreter will automatically support :program:`Emacs`\\ -like line " "editing and command-history keystrokes.)" msgstr "" +"一個旗標,預設為 true。若為 true,:meth:`cmdloop` 會使用 :func:`input` 來顯示" +"提示字元並讀取下一個命令;若為 false,則會改用 :data:`sys.stdout.write() " +"` 和 :data:`sys.stdin.readline() `。(這表示在支援的系" +"統中,透過 import :mod:`readline` module,直譯器將自動支援類似 :program:" +"`Emacs` 的列編輯與命令歷史快捷鍵。)" #: ../../library/cmd.rst:244 msgid "Cmd Example" -msgstr "" +msgstr "Cmd 範例" #: ../../library/cmd.rst:248 msgid "" "The :mod:`cmd` module is mainly useful for building custom shells that let a " "user work with a program interactively." msgstr "" +":mod:`cmd` module 主要用於建構自訂 shell,讓使用者能以互動方式操作程式。" #: ../../library/cmd.rst:251 msgid "" "This section presents a simple example of how to build a shell around a few " "of the commands in the :mod:`turtle` module." msgstr "" +"本節將示範如何以 :mod:`turtle` module 中的幾個命令為基礎,建立一個簡單的 " +"shell。" #: ../../library/cmd.rst:254 msgid "" @@ -350,6 +392,9 @@ msgid "" "converted to a number and dispatched to the turtle module. The docstring is " "used in the help utility provided by the shell." msgstr "" +"像是 :meth:`~turtle.forward` 這樣的基本 turtle 命令,可透過新增名為 :meth:`!" +"do_forward` 的方法加入至 :class:`Cmd` 子類別中。傳入的引數會轉換為數值,並傳" +"送給 turtle 模組。該方法的說明字串會用於 shell 所提供的說明功能中。" #: ../../library/cmd.rst:259 msgid "" @@ -359,6 +404,9 @@ msgid "" "do_playback` method reads the file and adds the recorded commands to the :" "attr:`~Cmd.cmdqueue` for immediate playback::" msgstr "" +"此範例同時包含一個簡單的錄製與重播功能,其實作方式是透過 :meth:`~Cmd.precmd` " +"方法,負責將輸入轉為小寫並寫入檔案。:meth:`!do_playback` 方法則會讀取該檔案," +"並將錄製的命令加入 :attr:`~Cmd.cmdqueue` 中以供立即重播::" #: ../../library/cmd.rst:265 msgid "" @@ -439,6 +487,79 @@ msgid "" "if __name__ == '__main__':\n" " TurtleShell().cmdloop()" msgstr "" +"import cmd, sys\n" +"from turtle import *\n" +"\n" +"class TurtleShell(cmd.Cmd):\n" +" intro = '歡迎來到 turtle shell。輸入 help 或 ? 來列出命令。\\n'\n" +" prompt = '(turtle) '\n" +" file = None\n" +"\n" +" # ----- 基本烏龜命令 -----\n" +" def do_forward(self, arg):\n" +" '將烏龜向前移動指定的距離: FORWARD 10'\n" +" forward(*parse(arg))\n" +" def do_right(self, arg):\n" +" '將烏龜右轉指定的角度: RIGHT 20'\n" +" right(*parse(arg))\n" +" def do_left(self, arg):\n" +" '將烏龜左轉指定的角度: LEFT 90'\n" +" left(*parse(arg))\n" +" def do_goto(self, arg):\n" +" '將烏龜移動到指定的絕對位置並改變方向。 GOTO 100 200'\n" +" goto(*parse(arg))\n" +" def do_home(self, arg):\n" +" '將烏龜返回起始位置: HOME'\n" +" home()\n" +" def do_circle(self, arg):\n" +" '畫出指定半徑、範圍和步數的圓: CIRCLE 50'\n" +" circle(*parse(arg))\n" +" def do_position(self, arg):\n" +" '顯示當前烏龜位置: POSITION'\n" +" print('當前位置是 %d %d\\n' % position())\n" +" def do_heading(self, arg):\n" +" '顯示當前烏龜方向角度: HEADING'\n" +" print('當前方向是 %d\\n' % (heading(),))\n" +" def do_color(self, arg):\n" +" '設定顏色: COLOR BLUE'\n" +" color(arg.lower())\n" +" def do_undo(self, arg):\n" +" '撤銷(重複)最後一次烏龜動作: UNDO'\n" +" def do_reset(self, arg):\n" +" '清除畫面並將烏龜返回到中心: RESET'\n" +" reset()\n" +" def do_bye(self, arg):\n" +" '停止錄製、關閉烏龜視窗並退出: BYE'\n" +" print('感謝使用 Turtle')\n" +" self.close()\n" +" bye()\n" +" return True\n" +"\n" +" # ----- 錄製與回放 -----\n" +" def do_record(self, arg):\n" +" '將未來命令儲存至檔案: RECORD rose.cmd'\n" +" self.file = open(arg, 'w')\n" +" def do_playback(self, arg):\n" +" '從檔案回放命令: PLAYBACK rose.cmd'\n" +" self.close()\n" +" with open(arg) as f:\n" +" self.cmdqueue.extend(f.read().splitlines())\n" +" def precmd(self, line):\n" +" line = line.lower()\n" +" if self.file and 'playback' not in line:\n" +" print(line, file=self.file)\n" +" return line\n" +" def close(self):\n" +" if self.file:\n" +" self.file.close()\n" +" self.file = None\n" +"\n" +"def parse(arg):\n" +" '將一串零個或多個數字轉換為引數 tuple'\n" +" return tuple(map(int, arg.split()))\n" +"\n" +"if __name__ == '__main__':\n" +" TurtleShell().cmdloop()" #: ../../library/cmd.rst:340 msgid "" @@ -446,6 +567,8 @@ msgid "" "using blank lines to repeat commands, and the simple record and playback " "facility:" msgstr "" +"以下是與 turtle shell 的一段範例互動,展示了說明功能、使用空白列重複執行命" +"令,以及簡單的錄製與重播功能:" #: ../../library/cmd.rst:343 msgid "" @@ -507,23 +630,23 @@ msgid "" "(turtle) bye\n" "Thank you for using Turtle" msgstr "" -"Welcome to the turtle shell. Type help or ? to list commands.\n" +"歡迎來到 turtle shell。輸入 help 或 ? 來列出命令。\n" "\n" "(turtle) ?\n" "\n" -"Documented commands (type help ):\n" +"已記錄的命令(輸入 help <主題>):\n" "========================================\n" "bye color goto home playback record right\n" "circle forward heading left position reset undo\n" "\n" "(turtle) help forward\n" -"Move the turtle forward by the specified distance: FORWARD 10\n" +"將烏龜向前移動指定的距離: FORWARD 10\n" "(turtle) record spiral.cmd\n" "(turtle) position\n" -"Current position is 0 0\n" +"當前位置是 0 0\n" "\n" "(turtle) heading\n" -"Current heading is 0\n" +"當前方向是 0\n" "\n" "(turtle) reset\n" "(turtle) circle 20\n" @@ -540,7 +663,7 @@ msgstr "" "(turtle) right 30\n" "(turtle) circle 120\n" "(turtle) heading\n" -"Current heading is 180\n" +"當前方向是 180\n" "\n" "(turtle) forward 100\n" "(turtle)\n" @@ -556,14 +679,14 @@ msgstr "" "(turtle) right 90\n" "(turtle) forward 300\n" "(turtle) playback spiral.cmd\n" -"Current position is 0 0\n" +"當前位置是 0 0\n" "\n" -"Current heading is 0\n" +"當前方向是 0\n" "\n" -"Current heading is 180\n" +"當前方向是 180\n" "\n" "(turtle) bye\n" -"Thank you for using Turtle" +"感謝使用 Turtle" #: ../../library/cmd.rst:74 msgid "? (question mark)"