From ac70900d76a42e8e1a352fa84d9becc5965d3061 Mon Sep 17 00:00:00 2001 From: BIT074 Date: Sun, 15 Nov 2026 19:04:54 +0800 Subject: [PATCH] complete json library translation --- library/json.po | 66 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/library/json.po b/library/json.po index b7568cac641..e05a44dd170 100644 --- a/library/json.po +++ b/library/json.po @@ -50,6 +50,8 @@ msgid "" "ambiguous. All values in Python are objects. In JSON, an object refers to " "any data wrapped in curly braces, similar to a Python dictionary." msgstr "" +"在 Python 中處理 JSON 時,「物件」一詞的意義可能不明確。Python 中的所有值都是" +"物件。在 JSON 中,物件指的是以大括號包住的任何資料,類似於 Python 字典。" #: ../../library/json.rst:27 msgid "" @@ -247,6 +249,20 @@ msgid "" ">>> list(ComplexEncoder().iterencode(2 + 1j))\n" "['[2.0', ', 1.0', ']']" msgstr "" +">>> import json\n" +">>> class ComplexEncoder(json.JSONEncoder):\n" +"... def default(self, obj):\n" +"... if isinstance(obj, complex):\n" +"... return [obj.real, obj.imag]\n" +"... # 讓基底類別的預設方法引發 TypeError\n" +"... return super().default(obj)\n" +"...\n" +">>> json.dumps(2 + 1j, cls=ComplexEncoder)\n" +"'[2.0, 1.0]'\n" +">>> ComplexEncoder().encode(2 + 1j)\n" +"'[2.0, 1.0]'\n" +">>> list(ComplexEncoder().iterencode(2 + 1j))\n" +"['[2.0', ', 1.0', ']']" #: ../../library/json.rst:124 msgid "Using :mod:`!json` from the shell to validate and pretty-print:" @@ -332,6 +348,9 @@ msgid "" "always produces :class:`str` objects, not :class:`bytes` objects, therefore " "``fp.write()`` must support :class:`str` input." msgstr "" +"將 *obj* 序列化後寫入的類檔案物件。:mod:`!json` 模組總是產生 :class:`str` " +"物件,而非 :class:`bytes` 物件,因此 ``fp.write()`` 必須支援 :class:`str` " +"輸入。" #: ../../library/json.rst:178 msgid "" @@ -339,6 +358,9 @@ msgid "" "class:`float`, :class:`bool`, ``None``) will be skipped instead of raising " "a :exc:`TypeError`. Default ``False``." msgstr "" +"若為 ``True``,則會略過非基本型別(:class:`str`、:class:`int`、" +":class:`float`、:class:`bool`、``None``)的鍵,而非引發 " +":exc:`TypeError`。預設為 ``False``。" #: ../../library/json.rst:184 msgid "" @@ -348,6 +370,9 @@ msgid "" "quotation mark, reverse solidus, and the control characters U+0000 through " "U+001F." msgstr "" +"若為 ``True``\\ (預設值),則保證輸出中所有輸入的非 ASCII 字元與不可列印字元" +"都會被跳脫。若為 ``False``,則所有字元都會原樣輸出,但必須跳脫的字元除外:" +"引號、反斜線,以及 U+0000 至 U+001F 的控制字元。" #: ../../library/json.rst:191 msgid "" @@ -377,6 +402,9 @@ msgid "" "overridden, for serializing into custom datatypes. If ``None`` (the " "default), :class:`!JSONEncoder` is used." msgstr "" +"若有設定,則為覆寫了 :meth:`~JSONEncoder.default` 方法的自訂 JSON 編碼器," +"用於序列化為自訂資料型別。若為 ``None``\\ (預設值),則使用 " +":class:`!JSONEncoder`。" #: ../../library/json.rst:210 msgid "" @@ -386,6 +414,9 @@ msgid "" "level. If zero, negative, or ``\"\"`` (the empty string), only newlines are " "inserted. If ``None`` (the default), no newlines are inserted." msgstr "" +"若為正整數或字串,則 JSON 陣列元素和物件成員會以該縮排層級美化輸出。正整數" +"表示每層縮排的空格數;字串(例如 ``\"\\t\"``)則用於每層的縮排。若為零、負數或 " +"``\"\"``\\ (空字串),則只插入換行。若為 ``None``\\ (預設值),則不插入換行。" #: ../../library/json.rst:220 msgid "" @@ -394,9 +425,10 @@ msgid "" "``(',', ': ')`` otherwise. For the most compact JSON, specify ``(',', ':')`` " "to eliminate whitespace." msgstr "" -"一個二元組:``(item_separator, key_separator)``。如為 ``None``\\ (預設值)" -"則 *separators* 被預設為 ``(', ', ': ')``,否則預設為 ``(',', ': ')``。想要獲" -"得最緊湊的 JSON 表示形式,你可以指定 ``(',', ':')`` 來消除空格。" +"一個二元組:``(item_separator, key_separator)``。若 *separators* 為 " +"``None``\\ (預設值),則當 *indent* 為 ``None`` 時使用 ``(', ', ': ')``," +"否則使用 ``(',', ': ')``。若要獲得最緊湊的 JSON 表示形式,請指定 " +"``(',', ':')`` 以消除空白字元。" #: ../../library/json.rst:229 msgid "" @@ -404,11 +436,15 @@ msgid "" "should return a JSON encodable version of the object or raise a :exc:" "`TypeError`. If ``None`` (the default), :exc:`!TypeError` is raised." msgstr "" +"遇到無法以其他方式序列化的物件時會被呼叫的函式。它應回傳該物件可供 JSON 編碼" +"的版本,或引發 :exc:`TypeError`。若為 ``None``\\ (預設值),則引發 " +":exc:`!TypeError`。" #: ../../library/json.rst:236 msgid "" "If ``True``, dictionaries will be outputted sorted by key. Default ``False``." msgstr "" +"若為 ``True``,則字典會依鍵排序後輸出。預設為 ``False``。" #: ../../library/json.rst:242 msgid "" @@ -432,7 +468,7 @@ msgstr "除了整數之外,*indent* 還允許使用字串作為輸入。" #: ../../library/json.rst:253 ../../library/json.rst:536 msgid "Use ``(',', ': ')`` as default if *indent* is not ``None``." -msgstr "如果 *indent* 不是 ``None``,則使用 ``(',', ': ')`` 作為預設值" +msgstr "如果 *indent* 不是 ``None``,則使用 ``(',', ': ')`` 作為預設值。" #: ../../library/json.rst:256 ../../library/json.rst:346 msgid "" @@ -462,6 +498,8 @@ msgid "" "A ``.read()``-supporting :term:`text file` or :term:`binary file` containing " "the JSON document to be deserialized." msgstr "" +"支援 ``.read()`` 且包含待去序列化 JSON 文件的\\ :term:`文字檔案 `" +"\\ 或\\ :term:`二進位檔案 `。" #: ../../library/json.rst:281 msgid "" @@ -469,6 +507,8 @@ msgid "" "will be passed to the constructor of *cls*. If ``None`` (the default), :" "class:`!JSONDecoder` is used." msgstr "" +"若有設定,則為自訂 JSON 解碼器。傳給 :func:`!load` 的額外關鍵字引數會傳遞給 " +"*cls* 的建構子。若為 ``None``\\ (預設值),則使用 :class:`!JSONDecoder`。" #: ../../library/json.rst:288 msgid "" @@ -528,6 +568,7 @@ msgstr "" #: ../../library/json.rst:0 msgid "Raises" msgstr "" +"引發" #: ../../library/json.rst:332 msgid "When the data being deserialized is not a valid JSON document." @@ -700,6 +741,9 @@ msgid "" "`dict`. This feature can be used to implement custom decoders. If " "*object_hook* is also defined, the *object_pairs_hook* takes priority." msgstr "" +"*object_pairs_hook* 是一個可選函式,會以每個 JSON 物件解碼後的有序對串列作為" +"引數來呼叫它。*object_pairs_hook* 的回傳值將用來取代 :class:`dict`。此功能" +"可用於實作自訂解碼器。若也定義了 *object_hook*,則 *object_pairs_hook* 優先。" #: ../../library/json.rst:416 msgid "Added support for *object_pairs_hook*." @@ -1146,6 +1190,16 @@ msgid "" ">>> json.loads('NaN')\n" "nan" msgstr "" +">>> # 這兩次呼叫都不會引發例外,但結果不是有效的 JSON\n" +">>> json.dumps(float('-inf'))\n" +"'-Infinity'\n" +">>> json.dumps(float('nan'))\n" +"'NaN'\n" +">>> # 去序列化時亦同\n" +">>> json.loads('-Infinity')\n" +"-inf\n" +">>> json.loads('NaN')\n" +"nan" #: ../../library/json.rst:682 msgid "" @@ -1270,6 +1324,8 @@ msgid "" "validate and pretty-print JSON objects. The :mod:`!json.tool` submodule " "implements this interface." msgstr "" +"可以透過 ``python -m json`` 將 :mod:`!json` 模組當作腳本呼叫,以驗證並美化" +"輸出 JSON 物件。:mod:`!json.tool` 子模組實作了此介面。" #: ../../library/json.rst:755 msgid "" @@ -1309,6 +1365,8 @@ msgid "" "For backwards compatibility, invoking the CLI as ``python -m json.tool`` " "remains supported." msgstr "" +"現在可以透過 ``python -m json`` 直接執行 :mod:`!json` 模組。為了維持向後相容" +"性,仍支援透過 ``python -m json.tool`` 呼叫命令列介面。" #: ../../library/json.rst:779 msgid "Command-line options"