Skip to content

Commit

Permalink
Fixed some bugs. Added tests for all supported extensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja committed May 6, 2021
1 parent 9f7f13a commit 403c55a
Show file tree
Hide file tree
Showing 11 changed files with 869 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package.json
package-lock.json
/node_modules/
prueba.html
prueba.po
prueba.md
output.txt

# Byte-compiled / optimized / DLL files
Expand Down
6 changes: 3 additions & 3 deletions docs/es/config.md.po
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ msgstr "Valor personalizado"
msgid "Documentation directories tree"
msgstr "Árbol de directorios de documentación"

msgid "true"
msgstr "true"

msgid "`language`: Translation language for the page."
msgstr "`language`: Idioma de traducción para la página."

Expand All @@ -164,6 +167,3 @@ msgstr ""
"`po`: Un objeto "
"[`polib.POFile`](https://polib.readthedocs.io/en/latest/api.html#polib.POFile)"
" con las traducciones cargadas."

msgid "true"
msgstr ""
29 changes: 16 additions & 13 deletions docs/es/extensions-support.md.po
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ msgstr ""

msgid ""
"Sometimes the translation should edit links. See the next example linking to"
" this documentation depending on the current language:"
" this documentation depending on the current active language:"
msgstr ""
"A veces la traducción debe editar enlaces. Observa el siguiente ejemplo "
"enlazando a esta documentación dependiendo del idioma actual:"
"enlazando a esta documentación dependiendo del idioma activo actual:"

msgid "You must let one blank line between each progress bar."
msgstr "Debes dejar una línea en blanco entre cada barra de progreso."
Expand Down Expand Up @@ -187,19 +187,19 @@ msgstr ""
"título traducido!\" mdpo }"

msgid "Hello, I'm text with ^^an insert^^."
msgstr "Hola, soy texto con ^^un insert^^."
msgstr "Hola, soy texto con ^^una inserción^^."

msgid "Hello, I'm text with^a\\ superscript^"
msgstr "Hola, soy texto con^un\\ sobreíndice^"
msgstr "Hola, soy texto con^un\\ superíndice^"

msgid "Open styled details"
msgstr "Detalles con estilo abierto"

msgid "Nested details!"
msgstr "Detalles anidados!"
msgstr "¡Detalles anidados!"

msgid "And more content again."
msgstr "Y más contenido de nuevo."
msgid "And more content."
msgstr "Y más contenido."

msgid "I :heart: mdpo"
msgstr "Me encanta mdpo :heart:"
Expand All @@ -209,12 +209,12 @@ msgstr ""
"Aquí hay algo de código: `#!py3 import pymdownx; pymdownx.__version__`."

msgid ""
"The mock shebang will be treated like text here: ` #!js var test = 0; `."
"The mock shebang will be treated like text here: ` #!js var test = 0;`."
msgstr ""
"El shebang simulado se tratará como texto aquí: ` #!js var test = 0; `."
"El shebang simulado se tratará como texto aquí: ` #!js var test = 0;`."

msgid ""
"You can access to the mdocs-mdpo-plugin documentation here: "
"You can access to the mkdocs-mdpo-plugin documentation here: "
"https://mondeja.github.io/mkdocs-mdpo-plugin"
msgstr ""
"Puedes acceder a la documentación de mkdocs-mdpo-plugin aquí: "
Expand All @@ -230,7 +230,7 @@ msgid "[=45% \"45%\"]"
msgstr "[=45% \"45 por ciento\"]"

msgid "[=100% \"100%\"]"
msgstr "[=100% \"cien por cien\"]"
msgstr "[=100% \"lleno\"]"

msgid "Here are some symbols: (tm) (c) (r)"
msgstr "Aquí hay algunos símbolos: (tm) (c) (r)"
Expand All @@ -245,10 +245,13 @@ msgid "Some inserted content from another file."
msgstr "Algo de contenido insertado desde otro archivo."

msgid "++ctrl+alt+delete++"
msgstr "++ctrl+alt+delete++"
msgstr "++ctrl+alt+f10++"

msgid "CH~3~CH~2~OH"
msgstr "CH~3~CH~2~OH"
msgstr "H~2~O"

msgid "Markdown"
msgstr "Markdown"

msgid "You must let a blank line between the term and its definition:"
msgstr "Debes dejar una línea en blanco entre el término y su definición:"
64 changes: 36 additions & 28 deletions docs/extensions-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ your PO file, you must add an attribute `mdpo`:
<!-- mdpo-disable-next-line -->
### [**`def_list`**](https://python-markdown.github.io/extensions/definition_lists)

You must let a blank line between the term and its definition:

=== "Output"

Apple
Expand All @@ -96,10 +98,12 @@ your PO file, you must add an attribute `mdpo`:

```markdown
Apple

: Pomaceous fruit of plants of the genus Malus in
the family Rosaceae.

Orange

: The fruit of an evergreen tree of the genus Citrus.
```

Expand Down Expand Up @@ -175,16 +179,15 @@ You must always let one newline between each footnote content:

```po
msgid "This is a footnote[^1]. This is another[^2]."
msgstr ""
msgstr "Esto es una nota al pie[^1]. Esto es otra[^2]."

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

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


<!-- mdpo-disable-next-line -->
### [**`tables`**](https://python-markdown.github.io/extensions/tables)

Expand All @@ -208,13 +211,13 @@ You must always let one newline between each footnote content:

```po
msgid "First header"
msgstr ""
msgstr "Primer encabezado"

msgid "Second header"
msgstr ""
msgstr "Segundo encabezado"

msgid "Content cell"
msgstr ""
msgstr "Contenido de celda"
```

<!-- mdpo-disable-next-line -->
Expand Down Expand Up @@ -246,16 +249,16 @@ You must always let one newline between each footnote content:

```po
msgid "Admonition title"
msgstr ""
msgstr "Título de advertencia"

msgid "The title will also be included in the PO file."
msgstr ""
msgstr "El título también será añadido en el archivo PO."

msgid "Note"
msgstr ""
msgstr "Nota"

msgid "Even the implicit title, which in this case would be \"Note\"."
msgstr ""
msgstr "Incluso el título implícito, el cual en este caso sería \"Nota\"."
```

## [PyMdown extensions](https://facelessuser.github.io/pymdown-extensions/extensions)
Expand All @@ -281,10 +284,10 @@ You must always let one newline between each footnote content:

```po
msgid "Hello, I'm text with ^^an insert^^."
msgstr ""
msgstr "Hola, soy texto con ^^una inserción^^."

msgid "Hello, I'm text with^a\\ superscript^."
msgstr ""
msgstr "Hola, soy texto con^un\\ superíndice^"
```

<!-- mdpo-disable-next-line -->
Expand All @@ -296,7 +299,7 @@ You must always let one newline between each footnote content:

??? danger "Nested details!"

And more content again.
And more content.

=== "Markdown"

Expand All @@ -305,20 +308,20 @@ You must always let one newline between each footnote content:

??? danger "Nested details!"

And more content again.
And more content.
```

=== "PO file content"

```po
msgid "Open styled details"
msgstr ""
msgstr "Detalles con estilo abierto"

msgid "Nested details!"
msgstr ""
msgstr "¡Detalles anidados!"

msgid "And more content again."
msgstr ""
msgid "And more content."
msgstr "Y más contenido."
```

<!-- mdpo-disable-next-line -->
Expand Down Expand Up @@ -384,25 +387,27 @@ There is no way of skip inline codespan blocks from being included in translatio

Here is some code: `#!py3 import pymdownx; pymdownx.__version__`.

The mock shebang will be treated like text here: ` #!js var test = 0; `.
The mock shebang will be treated like text here: ` #!js var test = 0;`.

=== "Markdown"

```markdown
Here is some code: `#!py3 import pymdownx; pymdownx.__version__`.

The mock shebang will be treated like text here: ` #!js var test = 0; `.
The mock shebang will be treated like text here: ` #!js var test = 0;`.
```

=== "PO file content"

```po
msgid "Here is some code: `#!py3 import pymdownx; pymdownx.__version__`."
msgstr ""
"Aquí hay algo de código: `#!py3 import pymdownx; pymdownx.__version__`."

msgid ""
"The mock shebang will be treated like text here: ` #!js var test = 0; `."
"The mock shebang will be treated like text here: ` #!js var test = 0;`."
msgstr ""
"El shebang simulado se tratará como texto aquí: ` #!js var test = 0;`."
```

<!-- mdpo-disable-next-line -->
Expand All @@ -422,30 +427,30 @@ There is no way of skip inline codespan blocks from being included in translatio

```po
msgid "++ctrl+alt+delete++"
msgstr ""
msgstr "++ctrl+alt+f10++"
```

<!-- mdpo-disable-next-line -->
### [**`pymdownx.magiclink`**](https://facelessuser.github.io/pymdown-extensions/extensions/magiclink)

Sometimes the translation should edit links. See the next example linking to
this documentation depending on the current language:
this documentation depending on the current active language:

=== "Output"

You can access to the mdocs-mdpo-plugin documentation here: https://mondeja.github.io/mkdocs-mdpo-plugin
You can access to the mkdocs-mdpo-plugin documentation here: https://mondeja.github.io/mkdocs-mdpo-plugin

=== "Markdown"

```markdown
You can access to the mdocs-mdpo-plugin documentation here: https://mondeja.github.io/mkdocs-mdpo-plugin
You can access to the mkdocs-mdpo-plugin documentation here: https://mondeja.github.io/mkdocs-mdpo-plugin
```

=== "PO file content"

```po
msgid ""
"You can access to the mdocs-mdpo-plugin documentation here: "
"You can access to the mkdocs-mdpo-plugin documentation here: "
"https://mondeja.github.io/mkdocs-mdpo-plugin"
msgstr ""
"Puedes acceder a la documentación de mkdocs-mdpo-plugin aquí: "
Expand Down Expand Up @@ -505,7 +510,7 @@ You must let one blank line between each progress bar.
msgstr "[=45% \"45 por ciento\"]"

msgid "[=100% \"100%\"]"
msgstr "[=100% \"cien por cien\"]"
msgstr "[=100% \"lleno\"]"
```

<!-- mdpo-disable-next-line -->
Expand Down Expand Up @@ -663,4 +668,7 @@ You must let one blank line between each progress bar.
```po
msgid "~~Delete me~~"
msgstr "~~Elimíname~~"

msgid "CH~3~CH~2~OH"
msgstr "H~2~O"
```
1 change: 1 addition & 0 deletions mkdocs_mdpo_plugin/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def process_translation(node, msgid):
node.text = entry.msgstr
entry.obsolete = False
elif msgid not in current_page._disabled_msgids:

current_page._po_msgids.append(msgid)
entry = polib.POEntry(msgid=msgid, msgstr='')
current_page._po.append(entry)
Expand Down
37 changes: 35 additions & 2 deletions mkdocs_mdpo_plugin/md4c_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,21 @@
pass


def build_text_md4c_parser_event(mkdocs_build_config):
EVENT_EXTENSIONS = {
'text': [
'admonition',
'def_list',
'pymdownx.details',
'pymdownx.snippets',
'pymdownx.tabbed',
],
'msgid': [
'def_list',
],
}


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

def text_event(md2po_instance, block, text):
Expand All @@ -50,4 +64,23 @@ def text_event(md2po_instance, block, text):
if re.match(TabbedProcessor.START, text):
md2po_instance.disabled_entries.append(text)
return False
return text_event

def msgid_event(md2po_instance, msgid):
if 'def_list' in md_extensions:
if msgid.startswith(': '):
md2po_instance._disable_next_line = True

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

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

return events
Loading

0 comments on commit 403c55a

Please sign in to comment.