| 1 |
# SOME DESCRIPTIVE TITLE. |
| 2 |
# Copyright (C) Kovid Goyal |
| 3 |
# This file is distributed under the same license as the calibre package. |
| 4 |
# |
| 5 |
# Translators: |
| 6 |
# RERBIN MA, 2025-2026 |
| 7 |
# tony shen <[email protected]>, 2024 |
| 8 |
# 美洁 黄 <[email protected]>, 2016 |
| 9 |
msgid "" |
| 10 |
msgstr "" |
| 11 |
"Project-Id-Version: calibre\n" |
| 12 |
"Report-Msgid-Bugs-To: \n" |
| 13 |
"POT-Creation-Date: 2026-02-25 10:21+0000\n" |
| 14 |
"PO-Revision-Date: 2014-11-21 02:54+0000\n" |
| 15 |
"Last-Translator: RERBIN MA, 2025-2026\n" |
| 16 |
"Language-Team: Chinese (China) (http://app.transifex.com/calibre/calibre/language/zh_CN/)\n" |
| 17 |
"MIME-Version: 1.0\n" |
| 18 |
"Content-Type: text/plain; charset=UTF-8\n" |
| 19 |
"Content-Transfer-Encoding: 8bit\n" |
| 20 |
"Language: zh_CN\n" |
| 21 |
"Plural-Forms: nplurals=1; plural=0;\n" |
| 22 |
|
| 23 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:2 |
| 24 |
msgid "Function mode for Search & replace in the Editor" |
| 25 |
msgstr "编辑器中搜索和替换功能" |
| 26 |
|
| 27 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:4 |
| 28 |
msgid "" |
| 29 |
"The :guilabel:`Search & replace` tool in the editor supports a *function " |
| 30 |
"mode*. In this mode, you can combine regular expressions (see :doc:`regexp`)" |
| 31 |
" with arbitrarily powerful Python functions to do all sorts of advanced text" |
| 32 |
" processing." |
| 33 |
msgstr "编辑器中的“查找与替换”工具支持“函数模式”。在此模式下,您可以将正则表达式与功能强大的自定义 Python 函数结合使用,从而实现各种高级文本处理任务。" |
| 34 |
|
| 35 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:9 |
| 36 |
msgid "" |
| 37 |
"In the standard *regexp* mode for search and replace, you specify both a " |
| 38 |
"regular expression to search for as well as a template that is used to " |
| 39 |
"replace all found matches. In function mode, instead of using a fixed " |
| 40 |
"template, you specify an arbitrary function, in the `Python programming " |
| 41 |
"language <https://docs.python.org>`_. This allows you to do lots of things " |
| 42 |
"that are not possible with simple templates." |
| 43 |
msgstr "在搜索和替换的标准 *regexp* 模式中,您指定要搜索的正则表达式以及用于替换所有找到的匹配项的模板。 在函数模式下,您不使用固定模板,而是在“Python 编程语言 <https://docs.python.org>”中指定任意函数。 这使您可以完成许多使用简单模板无法完成的事情。" |
| 44 |
|
| 45 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:16 |
| 46 |
msgid "" |
| 47 |
"Techniques for using function mode and the syntax will be described by means" |
| 48 |
" of examples, showing you how to create functions to perform progressively " |
| 49 |
"more complex tasks." |
| 50 |
msgstr "将通过示例描述使用函数模式和语法的技术,向您展示如何创建函数来执行逐渐复杂的任务。" |
| 51 |
|
| 52 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:21 |
| 53 |
msgid "The Function mode" |
| 54 |
msgstr "功能模式" |
| 55 |
|
| 56 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:26 |
| 57 |
msgid "Automatically fixing the case of headings in the document" |
| 58 |
msgstr "自动修复文档中标题的大小写" |
| 59 |
|
| 60 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:28 |
| 61 |
msgid "" |
| 62 |
"Here, we will leverage one of the builtin functions in the editor to " |
| 63 |
"automatically change the case of all text inside heading tags to title " |
| 64 |
"case::" |
| 65 |
msgstr "在这里,我们将利用编辑器中的内置函数之一自动将标题标签内所有文本的大小写更改为标题大小写:" |
| 66 |
|
| 67 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:33 |
| 68 |
msgid "" |
| 69 |
"For the function, simply choose the :guilabel:`Title-case text (ignore " |
| 70 |
"tags)` builtin function. This will change titles that look like: ``<h1>some " |
| 71 |
"titLE</h1>`` to ``<h1>Some Title</h1>``. It will work even if there are " |
| 72 |
"other HTML tags inside the heading tags." |
| 73 |
msgstr "对于函数,只需选择 :guilabel:`Title-case text (ignore tags)` 内置函数即可。它会将类似 ``<h1>some titLE</h1>`` 的标题更改为 ``<h1>Some Title</h1>``。即使标题标签内包含其他 HTML 标签,该函数也能正常工作。" |
| 74 |
|
| 75 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:40 |
| 76 |
msgid "Your first custom function - smartening hyphens" |
| 77 |
msgstr "您的第一个自定义函数 - 智能连字符" |
| 78 |
|
| 79 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:42 |
| 80 |
msgid "" |
| 81 |
"The real power of function mode comes from being able to create your own " |
| 82 |
"functions to process text in arbitrary ways. The Smarten Punctuation tool in" |
| 83 |
" the editor leaves individual hyphens alone, so you can use this function to" |
| 84 |
" replace them with em-dashes." |
| 85 |
msgstr "函数模式真正的强大之处在于,您可以创建自定义函数以任意方式处理文本。例如,编辑器自带的“规范标点符号”工具通常不会处理孤立的连字符,但通过自定义函数,您可以轻松地将它们批量替换为全角破折号(em-dashes)。" |
| 86 |
|
| 87 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:47 |
| 88 |
msgid "" |
| 89 |
"To create a new function, simply click the :guilabel:`Create/edit` button to" |
| 90 |
" create a new function and copy the Python code from below." |
| 91 |
msgstr "要创建新函数,只需单击“创建/编辑”按钮即可创建新函数并复制下面的 Python 代码。" |
| 92 |
|
| 93 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:55 |
| 94 |
msgid "" |
| 95 |
"Every :guilabel:`Search & replace` custom function must have a unique name " |
| 96 |
"and consist of a Python function named replace, that accepts all the " |
| 97 |
"arguments shown above. For the moment, we won't worry about all the " |
| 98 |
"different arguments to ``replace()`` function. Just focus on the ``match`` " |
| 99 |
"argument. It represents a match when running a search and replace. Its full " |
| 100 |
"documentation in available `here " |
| 101 |
"<https://docs.python.org/library/re.html#match-objects>`_. ``match.group()``" |
| 102 |
" simply returns all the matched text and all we do is replace hyphens in " |
| 103 |
"that text with em-dashes, first replacing double hyphens and then single " |
| 104 |
"hyphens." |
| 105 |
msgstr "每个“搜索和替换”自定义函数都必须有一个唯一的名称,并由一个名为“replace”的 Python 函数组成,该函数接受上面显示的所有参数。 目前,我们不必担心“replace()”函数的所有不同参数。 只需关注“match”参数即可。 它表示运行搜索和替换时的匹配。 其完整文档位于“此处 <https://docs.python.org/library/re.html#match-objects>”_。 ``match.group()`` 只是返回所有匹配的文本,我们所做的就是用破折号替换该文本中的连字符,首先替换双连字符,然后替换单连字符。" |
| 106 |
|
| 107 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:65 |
| 108 |
msgid "Use this function with the find regular expression::" |
| 109 |
msgstr "将此函数与查找正则表达式一起使用:" |
| 110 |
|
| 111 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:69 |
| 112 |
msgid "" |
| 113 |
"And it will replace all hyphens with em-dashes, but only in actual text and " |
| 114 |
"not inside HTML tag definitions." |
| 115 |
msgstr "它将用破折号替换所有 连字符,但仅限于实际文本中,而不是 HTML 标记定义内。" |
| 116 |
|
| 117 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:74 |
| 118 |
msgid "" |
| 119 |
"The power of function mode - using a spelling dictionary to fix mis-" |
| 120 |
"hyphenated words" |
| 121 |
msgstr "功能模式的力量 - 使用拼写词典来修复错误连字符的单词" |
| 122 |
|
| 123 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:76 |
| 124 |
msgid "" |
| 125 |
"Often, e-books created from scans of printed books contain mis-hyphenated " |
| 126 |
"words -- words that were split at the end of the line on the printed page. " |
| 127 |
"We will write a simple function to automatically find and fix such words." |
| 128 |
msgstr "通常,通过扫描印刷书籍创建的电子书包含错误连字符的单词,即在印刷页面上的行尾处分开的单词。 我们将编写一个简单的函数来自动查找并修复这些单词。" |
| 129 |
|
| 130 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:101 |
| 131 |
msgid "Use this function with the same find expression as before, namely::" |
| 132 |
msgstr "使用与之前相同的查找表达式来使用此函数,即:" |
| 133 |
|
| 134 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:105 |
| 135 |
msgid "" |
| 136 |
"And it will magically fix all mis-hyphenated words in the text of the book. " |
| 137 |
"The main trick is to use one of the useful extra arguments to the replace " |
| 138 |
"function, ``dictionaries``. This refers to the dictionaries the editor " |
| 139 |
"itself uses to spell check text in the book. What this function does is look" |
| 140 |
" for words separated by a hyphen, remove the hyphen and check if the " |
| 141 |
"dictionary recognizes the composite word, if it does, the original words are" |
| 142 |
" replaced by the hyphen free composite word." |
| 143 |
msgstr "它会神奇地修复书中所有错误连字符的单词。 主要技巧是使用替换函数的有用的额外参数之一“字典”。 这是指编辑器本身用来对书中文本进行拼写检查的词典。 该函数的作用是查找由连字符分隔的单词,删除连字符并检查字典是否识别该复合词,如果是,则将原始单词替换为无连字符的复合词。" |
| 144 |
|
| 145 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:113 |
| 146 |
msgid "" |
| 147 |
"Note that one limitation of this technique is it will only work for mono-" |
| 148 |
"lingual books, because, by default, ``dictionaries.recognized()`` uses the " |
| 149 |
"main language of the book." |
| 150 |
msgstr "请注意,此技术的一个限制是它仅适用于单语言书籍,因为默认情况下,“dictionaries.recognized()”使用书籍的主要语言。" |
| 151 |
|
| 152 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:119 |
| 153 |
msgid "Auto numbering sections" |
| 154 |
msgstr "自动编号章节" |
| 155 |
|
| 156 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:121 |
| 157 |
msgid "" |
| 158 |
"Now we will see something a little different. Suppose your HTML file has " |
| 159 |
"many sections, each with a heading in an :code:`<h2>` tag that looks like " |
| 160 |
":code:`<h2>Some text</h2>`. You can create a custom function that will " |
| 161 |
"automatically number these headings with consecutive section numbers, so " |
| 162 |
"that they look like :code:`<h2>1. Some text</h2>`." |
| 163 |
msgstr "现在我们会看到一些不同的东西。 假设您的 HTML 文件有许多部分,每个部分都有一个位于“<h2>”标记中的标题,看起来像“<h2>Some text</h2>”。 您可以创建一个自定义函数,自动使用连续的节号对这些标题进行编号,使它们看起来像“<h2> 1. Some text </h2>”。" |
| 164 |
|
| 165 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:137 |
| 166 |
msgid "Use it with the find expression::" |
| 167 |
msgstr "将其与查找表达式一起使用:" |
| 168 |
|
| 169 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:141 |
| 170 |
msgid "" |
| 171 |
"Place the cursor at the top of the file and click :guilabel:`Replace all`." |
| 172 |
msgstr "将光标置于文件顶部,然后单击“全部替换”。" |
| 173 |
|
| 174 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:143 |
| 175 |
msgid "" |
| 176 |
"This function uses another of the useful extra arguments to ``replace()``: " |
| 177 |
"the ``number`` argument. When doing a :guilabel:`Replace All` number is " |
| 178 |
"automatically incremented for every successive match." |
| 179 |
msgstr "该函数使用了另一个有用的额外参数“replace()”:“number”参数。 当执行“全部替换”时,每个连续匹配的数字都会自动增加。" |
| 180 |
|
| 181 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:147 |
| 182 |
msgid "" |
| 183 |
"Another new feature is the use of ``replace.file_order`` -- setting that to " |
| 184 |
"``'spine'`` means that if this search is run on multiple HTML files, the " |
| 185 |
"files are processed in the order in which they appear in the book. See " |
| 186 |
":ref:`file_order_replace_all` for details." |
| 187 |
msgstr "另一个新功能是使用“replace.file_order”——将其设置为“'spine”意味着如果在多个 HTML 文件上运行此搜索,则文件将按照它们出现的顺序进行处理。 这本书。 有关 详细信息,请参阅“file_order_replace_all”。" |
| 188 |
|
| 189 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:154 |
| 190 |
msgid "Auto create a Table of Contents" |
| 191 |
msgstr "自动创建目录" |
| 192 |
|
| 193 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:156 |
| 194 |
msgid "" |
| 195 |
"Finally, let's try something a little more ambitious. Suppose your book has " |
| 196 |
"headings in ``h1`` and ``h2`` tags that look like ``<h1 id=\"someid\">Some " |
| 197 |
"Text</h1>``. We will auto-generate an HTML Table of Contents based on these " |
| 198 |
"headings. Create the custom function below:" |
| 199 |
msgstr "最后,让我们尝试一个更宏大的目标。假设您的书中包含类似 <h1 id=\"someid\">标题内容</h1>格式的 h1 和 h2 标签。我们将基于这些标题自动生成一个 HTML 目录(TOC)。请创建如下自定义函数:" |
| 200 |
|
| 201 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:199 |
| 202 |
msgid "And use it with the find expression::" |
| 203 |
msgstr "并将其与 find 表达式一起使用:" |
| 204 |
|
| 205 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:203 |
| 206 |
msgid "" |
| 207 |
"Run the search on :guilabel:`All text files` and at the end of the search, a" |
| 208 |
" window will popup with \"Debug output from your function\" which will have " |
| 209 |
"the HTML Table of Contents, ready to be pasted into :file:`toc.html`." |
| 210 |
msgstr "在“所有文本文件”上运行搜索,在搜索结束时,将弹出一个窗口,其中显示“调试函数的输出”,其中包含 HTML 目录,可以粘贴到“toc.html”中。" |
| 211 |
|
| 212 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:207 |
| 213 |
msgid "" |
| 214 |
"The function above is heavily commented, so it should be easy to follow. The" |
| 215 |
" key new feature is the use of another useful extra argument to the " |
| 216 |
"``replace()`` function, the ``data`` object. The ``data`` object is a Python" |
| 217 |
" *dictionary* that persists between all successive invocations of " |
| 218 |
"``replace()`` during a single :guilabel:`Replace All` operation." |
| 219 |
msgstr "上面的函数有很多注释,所以应该很容易理解。 关键的新功能是对“replace()”函数使用另一个有用的额外参数,即“data”对象。 “data” 对象是一个 Python *字典*,在单个“全部替换”操作期间,在所有连续调用“replace()”之间持续存在。" |
| 220 |
|
| 221 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:213 |
| 222 |
msgid "" |
| 223 |
"Another new feature is the use of ``call_after_last_match`` -- setting that " |
| 224 |
"to ``True`` on the ``replace()`` function means that the editor will call " |
| 225 |
"``replace()`` one extra time after all matches have been found. For this " |
| 226 |
"extra call, the match object will be ``None``." |
| 227 |
msgstr "另一个新功能是使用“call_after_last_match”——在“replace()”函数上将其设置为“True”意味着编辑器将额外调用一次“replace()” 已找到匹配项。 对于这个额外的调用,匹配对象将为“None”。" |
| 228 |
|
| 229 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:218 |
| 230 |
msgid "" |
| 231 |
"This was just a demonstration to show you the power of function mode, if you" |
| 232 |
" really needed to generate a Table of Contents from headings in your book, " |
| 233 |
"you would be better off using the dedicated Table of Contents tool in " |
| 234 |
":guilabel:`Tools->Table of Contents`." |
| 235 |
msgstr "这只是一个演示,向您展示功能模式的强大功能,如果您确实需要根据书中的标题生成目录,您最好使用“工具”->“目录”中的专用目录工具 。" |
| 236 |
|
| 237 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:224 |
| 238 |
msgid "The API for the function mode" |
| 239 |
msgstr "功能模式的API" |
| 240 |
|
| 241 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:226 |
| 242 |
msgid "" |
| 243 |
"All function mode functions must be Python functions named replace, with the" |
| 244 |
" following signature::" |
| 245 |
msgstr "所有函数模式函数必须是名为replace的Python函数,具有以下签名:" |
| 246 |
|
| 247 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:232 |
| 248 |
msgid "" |
| 249 |
"When a find/replace is run, for every match that is found, the ``replace()``" |
| 250 |
" function will be called, it must return the replacement string for that " |
| 251 |
"match. If no replacements are to be done, it should return ``match.group()``" |
| 252 |
" which is the original string. The various arguments to the ``replace()`` " |
| 253 |
"function are documented below." |
| 254 |
msgstr "当运行查找/替换时,对于找到的每个匹配项,将调用“replace()”函数,它必须返回该匹配项的替换字符串。 如果不进行替换,则应返回原始字符串“match.group()”。 下面记录了“replace()”函数的各种参数。" |
| 255 |
|
| 256 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:239 |
| 257 |
msgid "The ``match`` argument" |
| 258 |
msgstr "“match” 参数" |
| 259 |
|
| 260 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:241 |
| 261 |
msgid "" |
| 262 |
"The ``match`` argument represents the currently found match. It is a `Python" |
| 263 |
" Match object <https://docs.python.org/library/re.html#match-objects>`_. Its" |
| 264 |
" most useful method is ``group()`` which can be used to get the matched text" |
| 265 |
" corresponding to individual capture groups in the search regular " |
| 266 |
"expression." |
| 267 |
msgstr "“match”参数代表当前找到的匹配。 它是一个`Python Match 对象<https://docs.python.org/library/re.html#match-objects>`_。 它最有用的方法是“group()”,它可用于获取与搜索正则表达式中的各个捕获组相对应的匹配文本。" |
| 268 |
|
| 269 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:248 |
| 270 |
msgid "The ``number`` argument" |
| 271 |
msgstr "``number`` 参数" |
| 272 |
|
| 273 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:250 |
| 274 |
msgid "" |
| 275 |
"The ``number`` argument is the number of the current match. When you run " |
| 276 |
":guilabel:`Replace All`, every successive match will cause ``replace()`` to " |
| 277 |
"be called with an increasing number. The first match has number 1." |
| 278 |
msgstr "``number`` 参数是当前匹配的编号。 当您运行“全部替换”时,每个连续的匹配都会导致以递增的数字调用“replace()”。 第一场比赛的号码为 1。" |
| 279 |
|
| 280 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:255 |
| 281 |
msgid "The ``file_name`` argument" |
| 282 |
msgstr "“file_name”参数" |
| 283 |
|
| 284 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:257 |
| 285 |
msgid "" |
| 286 |
"This is the filename of the file in which the current match was found. When " |
| 287 |
"searching inside marked text, the ``file_name`` is empty. The ``file_name`` " |
| 288 |
"is in canonical form, a path relative to the root of the book, using ``/`` " |
| 289 |
"as the path separator." |
| 290 |
msgstr "这是找到当前匹配项的文件的文件名。 在标记文本内搜索时,``file_name`` 为空。 “file_name” 是规范形式,是相对于本书根目录的路径,使用“/” 作为路径分隔符。" |
| 291 |
|
| 292 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:263 |
| 293 |
msgid "The ``metadata`` argument" |
| 294 |
msgstr "“metadata” 参数" |
| 295 |
|
| 296 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:265 |
| 297 |
msgid "" |
| 298 |
"This represents the metadata of the current book, such as title, authors, " |
| 299 |
"language, etc. It is an object of class " |
| 300 |
":class:`calibre.ebooks.metadata.book.base.Metadata`. Useful attributes " |
| 301 |
"include, ``title``, ``authors`` (a list of authors) and ``language`` (the " |
| 302 |
"language code)." |
| 303 |
msgstr "这代表当前书籍的元数据,例如标题、作者、语言等。它是`calibre.ebooks.metadata.book.base.Metadata` 类的对象。 有用的属性包括“标题”、“作者”(作者列表)和“语言”(语言代码)。" |
| 304 |
|
| 305 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:271 |
| 306 |
msgid "The ``dictionaries`` argument" |
| 307 |
msgstr "“dictionaries” 参数" |
| 308 |
|
| 309 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:273 |
| 310 |
msgid "" |
| 311 |
"This represents the collection of dictionaries used for spell checking the " |
| 312 |
"current book. Its most useful method is ``dictionaries.recognized(word)`` " |
| 313 |
"which will return ``True`` if the passed in word is recognized by the " |
| 314 |
"dictionary for the current book's language." |
| 315 |
msgstr "这代表用于对当前书籍进行拼写检查的词典集合。 它最有用的方法是“dictionaries.recognized(word)”,如果传入的单词被当前书籍语言的字典识别,它将返回“True”。" |
| 316 |
|
| 317 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:279 |
| 318 |
msgid "The ``data`` argument" |
| 319 |
msgstr "“data” 参数" |
| 320 |
|
| 321 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:281 |
| 322 |
msgid "" |
| 323 |
"This a simple Python ``dictionary``. When you run :guilabel:`Replace all`, " |
| 324 |
"every successive match will cause ``replace()`` to be called with the same " |
| 325 |
"``dictionary`` as data. You can thus use it to store arbitrary data between " |
| 326 |
"invocations of ``replace()`` during a :guilabel:`Replace all` operation." |
| 327 |
msgstr "这是一个简单的 Python“字典”。 当您运行“全部替换”时,每个连续的匹配都会导致使用与数据相同的“字典”来调用“replace()”。 因此,您可以使用它在“全部替换”操作期间调用“replace()”之间存储任意数据。" |
| 328 |
|
| 329 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:288 |
| 330 |
msgid "The ``functions`` argument" |
| 331 |
msgstr "“functions” 参数" |
| 332 |
|
| 333 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:290 |
| 334 |
msgid "" |
| 335 |
"The ``functions`` argument gives you access to all other user defined " |
| 336 |
"functions. This is useful for code re-use. You can define utility functions " |
| 337 |
"in one place and re-use them in all your other functions. For example, " |
| 338 |
"suppose you create a function named ``My Function`` like this:" |
| 339 |
msgstr "``functions`` 参数允许您访问所有其他用户定义的函数。这对于代码复用非常有用。您可以在一处定义通用工具函数,并在所有其他函数中重复使用它们。例如,假设您创建了一个名为 ``My Function`` 的函数,如下所示:" |
| 340 |
|
| 341 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:303 |
| 342 |
msgid "" |
| 343 |
"Then, in another function, you can access the ``utility()`` function like " |
| 344 |
"this:" |
| 345 |
msgstr "然后,在另一个函数中,您可以像这样访问“utility()”函数:" |
| 346 |
|
| 347 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:311 |
| 348 |
msgid "" |
| 349 |
"You can also use the functions object to store persistent data, that can be " |
| 350 |
"re-used by other functions. For example, you could have one function that " |
| 351 |
"when run with :guilabel:`Replace All` collects some data and another " |
| 352 |
"function that uses it when it is run afterwards. Consider the following two " |
| 353 |
"functions:" |
| 354 |
msgstr "您还可以使用函数对象来存储持久数据,这些数据可以被其他函数重用。 例如,您可以拥有一个函数,当使用“全部替换”运行时会收集一些数据,而另一个函数则在随后运行时使用这些数据。 考虑以下两个函数:" |
| 355 |
|
| 356 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:331 |
| 357 |
msgid "Debugging your functions" |
| 358 |
msgstr "调试你的函数" |
| 359 |
|
| 360 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:333 |
| 361 |
msgid "" |
| 362 |
"You can debug the functions you create by using the standard ``print()`` " |
| 363 |
"function from Python. The output of print will be displayed in a popup " |
| 364 |
"window after the Find/replace has completed. You saw an example of using " |
| 365 |
"``print()`` to output an entire table of contents above." |
| 366 |
msgstr "您可以使用 Python 中的标准“print()”函数来调试您创建的函数。 查找/替换完成后,打印的输出将显示在弹出窗口中。 您在上面看到了使用“print()”输出整个目录的示例。" |
| 367 |
|
| 368 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:341 |
| 369 |
msgid "Choose file order when running on multiple HTML files" |
| 370 |
msgstr "在多个 HTML 文件上运行时选择文件顺序" |
| 371 |
|
| 372 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:343 |
| 373 |
msgid "" |
| 374 |
"When you run a :guilabel:`Replace all` on multiple HTML files, the order in " |
| 375 |
"which the files are processed depends on what files you have open for " |
| 376 |
"editing. You can force the search to process files in the order in which " |
| 377 |
"they appear by setting the ``file_order`` attribute on your function, like " |
| 378 |
"this:" |
| 379 |
msgstr "当您对多个 HTML 文件执行“全部替换”时,文件的处理顺序取决于您打开进行编辑的文件。您可以通过在函数中设置``file_order``属性,强制搜索按文件在书籍中的出现顺序进行处理,示例如下:" |
| 380 |
|
| 381 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:355 |
| 382 |
msgid "" |
| 383 |
"``file_order`` accepts two values, ``spine`` and ``spine-reverse`` which " |
| 384 |
"cause the search to process multiple files in the order they appear in the " |
| 385 |
"book, either forwards or backwards, respectively." |
| 386 |
msgstr "``file_order`` 接受两个值,``spine`` 和 ``spine-reverse`` ,这两个值会导致搜索按照文件在书中出现的顺序,分别向前或向后,处理多个文件。" |
| 387 |
|
| 388 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:360 |
| 389 |
msgid "" |
| 390 |
"Having your function called an extra time after the last match is found" |
| 391 |
msgstr "在找到最后一个匹配项后额外调用您的函数" |
| 392 |
|
| 393 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:362 |
| 394 |
msgid "" |
| 395 |
"Sometimes, as in the auto generate table of contents example above, it is " |
| 396 |
"useful to have your function called an extra time after the last match is " |
| 397 |
"found. You can do this by setting the ``call_after_last_match`` attribute on" |
| 398 |
" your function, like this:" |
| 399 |
msgstr "有时,如上面的自动生成目录示例所示,在找到最后一个匹配项后额外调用函数会很有用。 您可以通过在函数上设置“call_after_last_match”属性来做到这一点,如下所示:" |
| 400 |
|
| 401 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:376 |
| 402 |
msgid "Appending the output from the function to marked text" |
| 403 |
msgstr "将函数的输出附加到标记的文本" |
| 404 |
|
| 405 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:378 |
| 406 |
msgid "" |
| 407 |
"When running search and replace on marked text, it is sometimes useful to " |
| 408 |
"append some text to the end of the marked text. You can do that by setting " |
| 409 |
"the ``append_final_output_to_marked`` attribute on your function (note that " |
| 410 |
"you also need to set ``call_after_last_match``), like this:" |
| 411 |
msgstr "在对“标记文本”执行搜索与替换时,有时需要在标记文本的末尾追加一些内容。您可以通过在函数中设置``append_final_output_to_marked`` 属性来实现这一点(请注意,您还需要同时设置``call_after_last_match``),示例如下:" |
| 412 |
|
| 413 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:393 |
| 414 |
msgid "Suppressing the result dialog when performing searches on marked text" |
| 415 |
msgstr "对标记文本执行搜索时禁止显示结果对话框" |
| 416 |
|
| 417 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:395 |
| 418 |
msgid "" |
| 419 |
"You can also suppress the result dialog (which can slow down the repeated " |
| 420 |
"application of a search/replace on many blocks of text) by setting the " |
| 421 |
"``suppress_result_dialog`` attribute on your function, like this:" |
| 422 |
msgstr "您还可以通过在函数上设置“suppress_result_dialog”属性来抑制结果对话框(这会减慢在许多文本块上重复应用搜索/替换的速度),如下所示:" |
| 423 |
|
| 424 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:408 |
| 425 |
msgid "More examples" |
| 426 |
msgstr "更多示例" |
| 427 |
|
| 428 |
#: ../../../__w/calibre/calibre/manual/function_mode.rst:410 |
| 429 |
msgid "" |
| 430 |
"More useful examples, contributed by calibre users, can be found in the " |
| 431 |
"`calibre E-book editor forum " |
| 432 |
"<https://www.mobileread.com/forums/showthread.php?t=237181>`_." |
| 433 |
msgstr "由 calibre 用户贡献的更多有用示例可以在 `calibre 电子书编辑器论坛 <https://www.mobileread.com/forums/showthread.php?t=237181>`_ 中找到。" |