Skip to content

Commit

Permalink
sync with cpython 08ccbb9b
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Oct 18, 2024
1 parent 713820c commit e6eb76d
Showing 1 changed file with 84 additions and 2 deletions.
86 changes: 84 additions & 2 deletions howto/argparse.po
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Python 3.13\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-09-24 07:20+0000\n"
"POT-Creation-Date: 2024-10-18 00:14+0000\n"
"PO-Revision-Date: 2023-12-11 17:33+0800\n"
"Last-Translator: Matt Wang <mattwang44@gmail.com>\n"
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
Expand Down Expand Up @@ -1222,6 +1222,7 @@ msgstr ""
" print(answer)"

#: ../../howto/argparse.rst:618 ../../howto/argparse.rst:656
#: ../../howto/argparse.rst:872
msgid "Output:"
msgstr "結果:"

Expand Down Expand Up @@ -1633,10 +1634,91 @@ msgid ""
msgstr "若要在 :mod:`argparse` 輸出中翻譯你自己的字串,請使用 :mod:`gettext`。"

#: ../../howto/argparse.rst:845
msgid "Custom type converters"
msgstr ""

#: ../../howto/argparse.rst:847
msgid ""
"The :mod:`argparse` module allows you to specify custom type converters for "
"your command-line arguments. This allows you to modify user input before "
"it's stored in the :class:`argparse.Namespace`. This can be useful when you "
"need to pre-process the input before it is used in your program."
msgstr ""

#: ../../howto/argparse.rst:852
msgid ""
"When using a custom type converter, you can use any callable that takes a "
"single string argument (the argument value) and returns the converted value. "
"However, if you need to handle more complex scenarios, you can use a custom "
"action class with the **action** parameter instead."
msgstr ""

#: ../../howto/argparse.rst:857
msgid ""
"For example, let's say you want to handle arguments with different prefixes "
"and process them accordingly::"
msgstr ""

#: ../../howto/argparse.rst:860
#, fuzzy
msgid ""
"import argparse\n"
"\n"
"parser = argparse.ArgumentParser(prefix_chars='-+')\n"
"\n"
"parser.add_argument('-a', metavar='<value>', action='append',\n"
" type=lambda x: ('-', x))\n"
"parser.add_argument('+a', metavar='<value>', action='append',\n"
" type=lambda x: ('+', x))\n"
"\n"
"args = parser.parse_args()\n"
"print(args)"
msgstr ""
"import argparse\n"
"parser = argparse.ArgumentParser()\n"
"parser.add_argument(\"square\", help=\"display a square of a given "
"number\",\n"
" type=int)\n"
"args = parser.parse_args()\n"
"print(args.square**2)"

#: ../../howto/argparse.rst:874
msgid ""
"$ python prog.py -a value1 +a value2\n"
"Namespace(a=[('-', 'value1'), ('+', 'value2')])"
msgstr ""

#: ../../howto/argparse.rst:879
#, fuzzy
msgid "In this example, we:"
msgstr "例如: ::"

#: ../../howto/argparse.rst:881
msgid ""
"Created a parser with custom prefix characters using the ``prefix_chars`` "
"parameter."
msgstr ""

#: ../../howto/argparse.rst:884
msgid ""
"Defined two arguments, ``-a`` and ``+a``, which used the ``type`` parameter "
"to create custom type converters to store the value in a tuple with the "
"prefix."
msgstr ""

#: ../../howto/argparse.rst:887
msgid ""
"Without the custom type converters, the arguments would have treated the ``-"
"a`` and ``+a`` as the same argument, which would have been undesirable. By "
"using custom type converters, we were able to differentiate between the two "
"arguments."
msgstr ""

#: ../../howto/argparse.rst:892
msgid "Conclusion"
msgstr "結論"

#: ../../howto/argparse.rst:847
#: ../../howto/argparse.rst:894
msgid ""
"The :mod:`argparse` module offers a lot more than shown here. Its docs are "
"quite detailed and thorough, and full of examples. Having gone through this "
Expand Down

0 comments on commit e6eb76d

Please sign in to comment.