@@ -11,7 +11,7 @@ msgid ""
1111msgstr ""
1212"Project-Id-Version : Python 3.12\n "
1313"Report-Msgid-Bugs-To : \n "
14- "POT-Creation-Date : 2024-07-29 04:36 +0000\n "
14+ "POT-Creation-Date : 2024-09-06 15:04 +0000\n "
1515"PO-Revision-Date : 2024-05-11 00:32+0000\n "
1616"
Last-Translator :
Rafael Fontenelle <[email protected] >, 2024\n "
1717"Language-Team : Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n "
@@ -81,6 +81,42 @@ msgstr "示例"
8181msgid "Example of customized Python always running in isolated mode::"
8282msgstr "定制的 Python 的示例总是会以隔离模式运行::"
8383
84+ #: ../../c-api/init_config.rst:41
85+ msgid ""
86+ "int main(int argc, char **argv)\n"
87+ "{\n"
88+ " PyStatus status;\n"
89+ "\n"
90+ " PyConfig config;\n"
91+ " PyConfig_InitPythonConfig(&config);\n"
92+ " config.isolated = 1;\n"
93+ "\n"
94+ " /* Decode command line arguments.\n"
95+ " Implicitly preinitialize Python (in isolated mode). */\n"
96+ " status = PyConfig_SetBytesArgv(&config, argc, argv);\n"
97+ " if (PyStatus_Exception(status)) {\n"
98+ " goto exception;\n"
99+ " }\n"
100+ "\n"
101+ " status = Py_InitializeFromConfig(&config);\n"
102+ " if (PyStatus_Exception(status)) {\n"
103+ " goto exception;\n"
104+ " }\n"
105+ " PyConfig_Clear(&config);\n"
106+ "\n"
107+ " return Py_RunMain();\n"
108+ "\n"
109+ "exception:\n"
110+ " PyConfig_Clear(&config);\n"
111+ " if (PyStatus_IsExit(status)) {\n"
112+ " return status.exitcode;\n"
113+ " }\n"
114+ " /* Display the error message and exit the process with\n"
115+ " non-zero exit code */\n"
116+ " Py_ExitStatusException(status);\n"
117+ "}"
118+ msgstr ""
119+
84120#: ../../c-api/init_config.rst:76
85121msgid "PyWideStringList"
86122msgstr "PyWideStringList"
@@ -223,6 +259,29 @@ msgstr ""
223259msgid "Example::"
224260msgstr "示例::"
225261
262+ #: ../../c-api/init_config.rst:191
263+ msgid ""
264+ "PyStatus alloc(void **ptr, size_t size)\n"
265+ "{\n"
266+ " *ptr = PyMem_RawMalloc(size);\n"
267+ " if (*ptr == NULL) {\n"
268+ " return PyStatus_NoMemory();\n"
269+ " }\n"
270+ " return PyStatus_Ok();\n"
271+ "}\n"
272+ "\n"
273+ "int main(int argc, char **argv)\n"
274+ "{\n"
275+ " void *ptr;\n"
276+ " PyStatus status = alloc(&ptr, 16);\n"
277+ " if (PyStatus_Exception(status)) {\n"
278+ " Py_ExitStatusException(status);\n"
279+ " }\n"
280+ " PyMem_Free(ptr);\n"
281+ " return 0;\n"
282+ "}"
283+ msgstr ""
284+
226285#: ../../c-api/init_config.rst:213
227286msgid "PyPreConfig"
228287msgstr "PyPreConfig"
@@ -393,9 +452,9 @@ msgstr "设置 :c:member:`PyConfig.filesystem_errors` 为 ``\"replace\"``."
393452
394453#: ../../c-api/init_config.rst:314
395454msgid ""
396- "Initialized the from :envvar:`PYTHONLEGACYWINDOWSFSENCODING` environment "
455+ "Initialized from the :envvar:`PYTHONLEGACYWINDOWSFSENCODING` environment "
397456"variable value."
398- msgstr "初始化来自 :envvar:`PYTHONLEGACYWINDOWSFSENCODING` 的环境变量值。 "
457+ msgstr ""
399458
400459#: ../../c-api/init_config.rst:317 ../../c-api/init_config.rst:894
401460msgid ""
@@ -565,6 +624,26 @@ msgid ""
565624"<utf8-mode>`::"
566625msgstr "使用预初始化来启用 :ref:`Python UTF-8 模式 <utf8-mode>` 的例子::"
567626
627+ #: ../../c-api/init_config.rst:414
628+ msgid ""
629+ "PyStatus status;\n"
630+ "PyPreConfig preconfig;\n"
631+ "PyPreConfig_InitPythonConfig(&preconfig);\n"
632+ "\n"
633+ "preconfig.utf8_mode = 1;\n"
634+ "\n"
635+ "status = Py_PreInitialize(&preconfig);\n"
636+ "if (PyStatus_Exception(status)) {\n"
637+ " Py_ExitStatusException(status);\n"
638+ "}\n"
639+ "\n"
640+ "/* at this point, Python speaks UTF-8 */\n"
641+ "\n"
642+ "Py_Initialize();\n"
643+ "/* ... use Python API here ... */\n"
644+ "Py_Finalize();"
645+ msgstr ""
646+
568647#: ../../c-api/init_config.rst:433
569648msgid "PyConfig"
570649msgstr "PyConfig"
@@ -1882,6 +1961,35 @@ msgstr "当前的配置 (``PyConfig`` 类型) 保存在 ``PyInterpreterState.con
18821961msgid "Example setting the program name::"
18831962msgstr "设置程序名称的示例::"
18841963
1964+ #: ../../c-api/init_config.rst:1316
1965+ msgid ""
1966+ "void init_python(void)\n"
1967+ "{\n"
1968+ " PyStatus status;\n"
1969+ "\n"
1970+ " PyConfig config;\n"
1971+ " PyConfig_InitPythonConfig(&config);\n"
1972+ "\n"
1973+ " /* Set the program name. Implicitly preinitialize Python. */\n"
1974+ " status = PyConfig_SetString(&config, &config.program_name,\n"
1975+ " L\" /path/to/my_program\" );\n"
1976+ " if (PyStatus_Exception(status)) {\n"
1977+ " goto exception;\n"
1978+ " }\n"
1979+ "\n"
1980+ " status = Py_InitializeFromConfig(&config);\n"
1981+ " if (PyStatus_Exception(status)) {\n"
1982+ " goto exception;\n"
1983+ " }\n"
1984+ " PyConfig_Clear(&config);\n"
1985+ " return;\n"
1986+ "\n"
1987+ "exception:\n"
1988+ " PyConfig_Clear(&config);\n"
1989+ " Py_ExitStatusException(status);\n"
1990+ "}"
1991+ msgstr ""
1992+
18851993#: ../../c-api/init_config.rst:1342
18861994msgid ""
18871995"More complete example modifying the default configuration, read the "
@@ -1893,6 +2001,61 @@ msgstr ""
18932001"更完整的示例会修改默认配置,读取配置,然后覆盖某些参数。 请注意自 3.11 "
18942002"版开始,许多参数在初始化之前不会被计算,因此无法从配置结构体中读取值。在调用初始化之前设置的任何值都将不会被初始化操作改变::"
18952003
2004+ #: ../../c-api/init_config.rst:1349
2005+ msgid ""
2006+ "PyStatus init_python(const char *program_name)\n"
2007+ "{\n"
2008+ " PyStatus status;\n"
2009+ "\n"
2010+ " PyConfig config;\n"
2011+ " PyConfig_InitPythonConfig(&config);\n"
2012+ "\n"
2013+ " /* Set the program name before reading the configuration\n"
2014+ " (decode byte string from the locale encoding).\n"
2015+ "\n"
2016+ " Implicitly preinitialize Python. */\n"
2017+ " status = PyConfig_SetBytesString(&config, &config.program_name,\n"
2018+ " program_name);\n"
2019+ " if (PyStatus_Exception(status)) {\n"
2020+ " goto done;\n"
2021+ " }\n"
2022+ "\n"
2023+ " /* Read all configuration at once */\n"
2024+ " status = PyConfig_Read(&config);\n"
2025+ " if (PyStatus_Exception(status)) {\n"
2026+ " goto done;\n"
2027+ " }\n"
2028+ "\n"
2029+ " /* Specify sys.path explicitly */\n"
2030+ " /* If you want to modify the default set of paths, finish\n"
2031+ " initialization first and then use PySys_GetObject(\" path\" ) */\n"
2032+ " config.module_search_paths_set = 1;\n"
2033+ " status = PyWideStringList_Append(&config.module_search_paths,\n"
2034+ " L\" /path/to/stdlib\" );\n"
2035+ " if (PyStatus_Exception(status)) {\n"
2036+ " goto done;\n"
2037+ " }\n"
2038+ " status = PyWideStringList_Append(&config.module_search_paths,\n"
2039+ " L\" /path/to/more/modules\" );\n"
2040+ " if (PyStatus_Exception(status)) {\n"
2041+ " goto done;\n"
2042+ " }\n"
2043+ "\n"
2044+ " /* Override executable computed by PyConfig_Read() */\n"
2045+ " status = PyConfig_SetString(&config, &config.executable,\n"
2046+ " L\" /path/to/my_executable\" );\n"
2047+ " if (PyStatus_Exception(status)) {\n"
2048+ " goto done;\n"
2049+ " }\n"
2050+ "\n"
2051+ " status = Py_InitializeFromConfig(&config);\n"
2052+ "\n"
2053+ "done:\n"
2054+ " PyConfig_Clear(&config);\n"
2055+ " return status;\n"
2056+ "}"
2057+ msgstr ""
2058+
18962059#: ../../c-api/init_config.rst:1405
18972060msgid "Isolated Configuration"
18982061msgstr "隔离配置"
@@ -2353,3 +2516,40 @@ msgid ""
23532516"Example running Python code between \" Core\" and \" Main\" initialization "
23542517"phases::"
23552518msgstr "在“核心”和“主要”初始化阶段之间运行 Python 代码的示例::"
2519+
2520+ #: ../../c-api/init_config.rst:1611
2521+ msgid ""
2522+ "void init_python(void)\n"
2523+ "{\n"
2524+ " PyStatus status;\n"
2525+ "\n"
2526+ " PyConfig config;\n"
2527+ " PyConfig_InitPythonConfig(&config);\n"
2528+ " config._init_main = 0;\n"
2529+ "\n"
2530+ " /* ... customize 'config' configuration ... */\n"
2531+ "\n"
2532+ " status = Py_InitializeFromConfig(&config);\n"
2533+ " PyConfig_Clear(&config);\n"
2534+ " if (PyStatus_Exception(status)) {\n"
2535+ " Py_ExitStatusException(status);\n"
2536+ " }\n"
2537+ "\n"
2538+ " /* Use sys.stderr because sys.stdout is only created\n"
2539+ " by _Py_InitializeMain() */\n"
2540+ " int res = PyRun_SimpleString(\n"
2541+ " \" import sys; \" \n"
2542+ " \" print('Run Python code before _Py_InitializeMain', \" \n"
2543+ " \" file=sys.stderr)\" );\n"
2544+ " if (res < 0) {\n"
2545+ " exit(1);\n"
2546+ " }\n"
2547+ "\n"
2548+ " /* ... put more configuration code here ... */\n"
2549+ "\n"
2550+ " status = _Py_InitializeMain();\n"
2551+ " if (PyStatus_Exception(status)) {\n"
2552+ " Py_ExitStatusException(status);\n"
2553+ " }\n"
2554+ "}"
2555+ msgstr ""
0 commit comments