********************** Customizing extraction ********************** You can customize the string extraction process using HTML comments in your Markdown files. .. tip:: If you want to specify next commands with other names, take a look at the argument :ref:`md2po---command-alias` of :ref:`md2po CLI` or the optional parameter ``command_aliases`` of the :doc:`programmatic APIs`. Disabling extraction ==================== You can disable and enable the extraction of certain strings using the next HTML commments: * ```` or ````: Do not extract the next Markdown block. * ````: Do not extract the content after it. * ````: Extract the content after it. * ```` or ```` Extract the next Markdown block. .. rubric:: Example: .. code-block:: python >>> from mdpo.md2po import markdown_to_pofile >>> md_content = '''# Header ... ... This will be included ... ... ... This will be ignored. ... ... This will be included also. ... ... ... This paragraph compounded by multiples ... lines will be ignored. ... ... # md2po remains disabled for this header ... ... ... This line will be included because we have enabled it individually. ... ... ... All content from here will be extracted... ... ''' >>> >>> pofile = markdown_to_pofile(md_content) >>> print(pofile) # msgid "" msgstr "" msgid "This will be included." msgstr "" msgid "This will be included also." msgstr "" msgid "This line will be included because we have enabled it individually." msgstr "" msgid "All content from here will be extracted..." msgstr "" Including comments for translators ================================== You can include comments for translators using the next line in the line before the message: * ```` .. rubric:: Example: .. code-block:: python >>> content = ''' ... Some text that needs to be clarified ... ... Some text without comment ... ''' >>> pofile = markdown_to_pofile(content) >>> print(pofile) # msgid "" msgstr "" #. This is a comment for a translator msgid "Some text that needs to be clarified" msgstr "" msgid "Some text without comment" msgstr "" Contextual markers ================== You can specify contexts for msgids using next command: * ```` .. rubric:: Example: .. code-block:: python >>> content = ''' ... May ... ... ... May ... ''' >>> >>> pofile = markdown_to_pofile(content) >>> print(pofile) # msgid "" msgstr "" msgctxt "month" msgid "May" msgstr "" msgctxt "might" msgid "May" msgstr "" .. _include-codeblock-command: Code blocks extraction ====================== You can enable and disable code blocks extraction inside the PO file using the next commands: * ````: Include all codeblocks placed after this command (same behaviour as passing the argument :ref:`md2po---include-codeblocks` or ``include_codeblocks=True`` if you are using the :doc:`programmatic interface `). * ````: Does not include codeblocks placed after this command. * ````: Include next codeblock placed after this command. * ````: Does not include next codeblock placed after this command. .. rubric:: Indented code block example: .. code-block:: python >>> content = ''' ... ... ... var hello = "world"; ... var hola = "mundo"; ... ... Another paragraph. ... ''' >>> >>> pofile = markdown_to_pofile(content) >>> print(pofile) msgid "" msgstr "" msgid "" "var hello = \"world\";\n" "var hola = \"mundo\";\n" msgstr "" msgid "Another paragraph." msgstr "" .. rubric:: Fenced code block example: .. code-block:: python >>> content = ''' ... ... ```javascript ... var hello = "world"; ... var hola = "mundo"; ... ``` ... ''' >>> >>> pofile = markdown_to_pofile(content) >>> print(pofile) msgid "" msgstr "" msgid "" "var hello = \"world\";\n" "var hola = \"mundo\";\n" msgstr "" Extracting comments itself ========================== You can extract comments inside the PO file, but don't ask me why you need this: * ```` .. rubric:: Example: .. code-block:: python >>> content = ''' ... Some text ... ''' >>> pofile = markdown_to_pofile(content) >>> print(pofile) # msgid "" msgstr "" msgid "This message will be included" msgstr "" msgid "Some text" msgstr "" This command can be used along with ``mdpo-translator``: .. code-block:: python >>> content = ''' ... ... Some text that needs to be clarified ... ''' >>> pofile = markdown_to_pofile(content) >>> print(pofile) # msgid "" msgstr "" #. Comment for translator in comment msgid "This comment must be included" msgstr "" And with ``mdpo-context``, combining both: .. code-block:: python >>> content = ''' ... ... ... Some text that needs to be clarified ... ''' >>> pofile = markdown_to_pofile(content) >>> print(pofile) # msgid "" msgstr "" #. Comment for translator in comment msgctxt "Some context for the included" msgid "This comment must be included" msgstr ""