Skip to content

Commit

Permalink
- Fix errors translating footnotes when other links are used in the s…
Browse files Browse the repository at this point in the history
…ame page.

- Fix error extracting messages repeated between content and page title.
- Don't use message contexts for page titles.
- Add tests for `mkdocs-exclude` plugin.
  • Loading branch information
mondeja committed May 14, 2021
1 parent 3b662e7 commit 61177b6
Show file tree
Hide file tree
Showing 18 changed files with 299 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.6
current_version = 0.0.7

[bumpversion:file:mkdocs_mdpo_plugin/__init__.py]

Expand Down
19 changes: 12 additions & 7 deletions docs/es/_compendium.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@
msgid ""
msgstr ""

msgid "Extensions support"
msgstr "Soporte de extensiones"

msgid "Permanent link"
msgstr "Link permanente"

msgctxt "Page title"
msgid "Configuration"
msgstr "Configuración"

msgid "Note"
msgstr "Nota"

Expand All @@ -37,3 +30,15 @@ msgstr "Debes dejar una línea en blanco entre el término y su definición:"

msgid "Markdown"
msgstr "Markdown"

msgid "Plugins support"
msgstr "Soporte de plugins"

msgid "Extensions support"
msgstr "Soporte de extensiones"

#~ msgid "[^1]: This \"is a footnote content.\""
#~ msgstr ""

#~ msgid "[^2]: This \"is another footnote content.\""
#~ msgstr ""
18 changes: 4 additions & 14 deletions docs/es/config.md.po
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.4.3\n"

msgid ""
"Always put `mdpo` plugin in `mkdocs.yml` file after other plugins which "
"could edit the content of your files:"
msgstr ""
"Siempre pon el plugin `mdpo` en el archivo `mkdocs.yml` después de otros "
"Siempre coloca el plugin `mdpo` en el archivo `mkdocs.yml` después de otros "
"plugins que pudieran editar el contenido de tus archivos:"

msgid ""
Expand Down Expand Up @@ -58,8 +48,8 @@ msgid ""
"Original language of your files. If not defined, the first language found in"
" [`languages`](#languages-list) will be used."
msgstr ""
"Idioma original de tus archivos. Si no se define, el primer idioma "
"encontrado en [`languages`](#languages-list) será usado."
"Idioma original de tus archivos. Si no se define se usará el primer idioma "
"encontrado en [`languages`](#languages-list)."

msgid ""
"Defining it to `locale`, the layout will change a bit, but this doesn't mean"
Expand Down Expand Up @@ -190,4 +180,4 @@ msgstr ""
"de idioma][mkdocs-material-site-language-selector])."

msgid "Configuration"
msgstr ""
msgstr "Configuración"
25 changes: 7 additions & 18 deletions docs/es/extensions-support/oficial.md.po
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.4.3\n"

msgctxt "Page title"

msgid "Official extensions"
msgstr "Extensiones oficiales"

Expand All @@ -29,12 +18,6 @@ msgid "You must always let one newline between each footnote content:"
msgstr ""
"Siempre debes dejar una línea en blanco entre cada contenido de nota al pie:"

msgid "[^1]: This is a footnote content."
msgstr "[^1]: Este es un contenido de nota al pie."

msgid "[^2]: This is another footnote content."
msgstr "[^2]: Este es otro contenido de nota al pie."

msgid ""
"Only `title` attributes values are translated. Currently, this extension is "
"a bit tricky because, if you want to see the `title` attribute value "
Expand Down Expand Up @@ -103,3 +86,9 @@ msgid ""
msgstr ""
"[officially-supported-extensions]: https://python-"
"markdown.github.io/extensions/#officially-supported-extensions"

msgid "[^1]: This is a footnote content."
msgstr "[^1]: Esto es el contenido de una nota al pie."

msgid "[^2]: This is another footnote content."
msgstr "[^2]: Esto es el contenido de otra nota al pie."
13 changes: 1 addition & 12 deletions docs/es/extensions-support/pymdownx.md.po
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.4.3\n"

msgctxt "Page title"

msgid "PyMdown extensions"
msgstr "Extensiones PyMdown"

Expand Down
11 changes: 0 additions & 11 deletions docs/es/index.md.po
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.4.3\n"

msgctxt "Page title"
msgid "Home"
msgstr "Inicio"

Expand Down
18 changes: 18 additions & 0 deletions docs/es/plugins-support/navigation-and-page-building.md.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
msgid ""
msgstr ""

msgid "Navigation and page building"
msgstr "Navegación y construcción de páginas"

msgid ""
"[navigation-and-page-building]: "
"https://github.com/mkdocs/mkdocs/wiki/MkDocs-Plugins#navigation--page-"
"building"
msgstr ""
"[navigation-and-page-building]: "
"https://github.com/mkdocs/mkdocs/wiki/MkDocs-Plugins#navigation--page-"
"building"

msgid "[Navigation and page building][navigation-and-page-building]"
msgstr "[Navegación y construcción de páginas][navigation-and-page-building]"
4 changes: 2 additions & 2 deletions docs/extensions-support/oficial.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ You must always let one newline between each footnote content:
msgstr "Esto es una nota al pie[^1]. Esto es otra[^2]."

msgid "[^1]: This is a footnote content."
msgstr "[^1]: Este es un contenido de nota al pie."
msgstr "[^1]: Esto es el contenido de una nota al pie."

msgid "[^2]: This is another footnote content."
msgstr "[^2]: Este es otro contenido de nota al pie."
msgstr "[^2]: Esto es el contenido de otra nota al pie"
```

<!-- mdpo-disable-next-line -->
Expand Down
8 changes: 8 additions & 0 deletions docs/plugins-support/navigation-and-page-building.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# [Navigation and page building][navigation-and-page-building]

<!-- mdpo-disable -->
- [x] [mkdocs-exclude](https://github.com/apenwarr/mkdocs-exclude)

<!-- mdpo-enable -->

[navigation-and-page-building]: https://github.com/mkdocs/mkdocs/wiki/MkDocs-Plugins#navigation--page-building
4 changes: 4 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ nav:
- Extensions support:
- Official extensions: extensions-support/oficial.md
- PyMdown extensions: extensions-support/pymdownx.md
- Plugins support:
- Navigation and page building: plugins-support/navigation-and-page-building.md

markdown_extensions:
- toc:
Expand Down Expand Up @@ -67,6 +69,8 @@ plugins:
glob:
- file-to-be-inserted.txt
- mdpo
- minify:
minify_html: true

extra:
alternate:
Expand Down
2 changes: 1 addition & 1 deletion mkdocs_mdpo_plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""mkdocs-mdpo-plugin package"""

__version__ = '0.0.6'
__version__ = '0.0.7'
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
pass


EVENT_EXTENSIONS = {
MD2PO_EVENT_EXTENSIONS = {
'text': [
'admonition',
'def_list',
Expand All @@ -32,10 +32,19 @@
'msgid': [
'def_list',
],
'link_reference': [
'footnotes',
],
}

PO2MD_EVENT_EXTENSIONS = {
'link_reference': [
'footnotes',
],
}


def build_md4c_parser_events(mkdocs_build_config):
def build_md2po_events(mkdocs_build_config):
md_extensions = mkdocs_build_config['markdown_extensions']

def text_event(md2po_instance, block, text):
Expand All @@ -57,22 +66,47 @@ def text_event(md2po_instance, block, text):
return False

def msgid_event(md2po_instance, msgid):
if 'def_list' in md_extensions:
if msgid.startswith(': '):
md2po_instance._disable_next_line = True
if 'footnotes' in md_extensions:
# footnotes are parsed like link references
if msgid.startswith('[^'):
md2po_instance._disable_next_line = True
if msgid.startswith(': '):
md2po_instance._disable_next_line = True

def link_reference_event(md2po_instance, target, *args):
if target.startswith('^'):
return False

# load only those events required for the extensions
events_functions = {
'text': text_event,
'msgid': msgid_event,
'link_reference': link_reference_event,
}

events = {}
for event_name, extensions in MD2PO_EVENT_EXTENSIONS.items():
for extension in extensions:
if extension in md_extensions:
events[event_name] = events_functions[event_name]
break

return events


def build_po2md_events(mkdocs_build_config):
md_extensions = mkdocs_build_config['markdown_extensions']

def link_reference_event(po2md_instance, target, href, title):
# footnotes
if target.startswith('^'):
# footnotes are treated as text blocks, so we don't need to
# translate them here
return False

# load only those events required for the extensions
events_functions = {
'link_reference': link_reference_event,
}

events = {}
for event_name, extensions in EVENT_EXTENSIONS.items():
for event_name, extensions in PO2MD_EVENT_EXTENSIONS.items():
for extension in extensions:
if extension in md_extensions:
events[event_name] = events_functions[event_name]
Expand Down
Loading

0 comments on commit 61177b6

Please sign in to comment.