Skip to content

Commit

Permalink
Fix not used language pofiles entries not being properly marked as ob…
Browse files Browse the repository at this point in the history
…soletes
  • Loading branch information
mondeja committed May 7, 2021
1 parent 8a0c066 commit 0a2987a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 16 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.5

[bumpversion:file:mkdocs_mdpo_plugin/__init__.py]

Expand Down
6 changes: 3 additions & 3 deletions docs/es/extensions-support/oficial.md.po
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ msgstr ""
"extensión es un poco complicada porque, si quieres ver el valor del atributo"
" `title` incluído en un archivo PO, debes añadir un atributo `mdpo`:"

msgid "The HTML specification is maintained by the W3C."
msgstr ""

msgid ""
"[link](https://mondeja.github.io/mkdocs-mdpo-plugin){: title=\"With a "
"translated title!\" mdpo }"
Expand Down Expand Up @@ -99,3 +96,6 @@ msgstr "Volver a la nota al pie 2 en el texto"

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

msgid "The HTML specification is maintained by the W3C."
msgstr "La especificación HTML es mantenida por el W3C."
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.5'
17 changes: 16 additions & 1 deletion mkdocs_mdpo_plugin/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@ def process_translation(node, msgid):
if entry.msgid == msgid:
if entry.msgstr:
node.text = entry.msgstr
(
current_page._translated_entries_msgstrs
).append(
entry.msgstr,
)
entry.obsolete = False
current_page._translated_entries_msgids.append(
entry.msgid,
)
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 Expand Up @@ -74,7 +81,15 @@ def process_translation(node, msgid):
if entry.msgid == msgid:
if entry.msgstr:
node.attrib['title'] = entry.msgstr
(
current_page._translated_entries_msgstrs
).append(
entry.msgstr,
)
entry.obsolete = False
current_page._translated_entries_msgids.append(
entry.msgid,
)
elif msgid not in current_page._disabled_msgids:
current_page._po_msgids.append(msgid)
entry = polib.POEntry(msgid=msgid, msgstr='')
Expand Down
29 changes: 20 additions & 9 deletions mkdocs_mdpo_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,17 +505,15 @@ def on_page_markdown(self, markdown, page, config, files):
new_page._po = po
new_page._po_filepath = po_filepath

new_page._po_msgids = []
new_page._po_msgids = [entry.msgid for entry in po]
new_page._translated_entries_msgstrs = []
new_page._disabled_msgids = []
new_page._translated_entries_msgids = []
new_page._disabled_msgids = [
entry.msgid for entry in po2md.disabled_entries
]
for entry in po2md.translated_entries:
new_page._translated_entries_msgstrs.append(
polib.unescape(entry.msgstr),
)
for entry in po:
new_page._po_msgids.append(polib.unescape(entry.msgid))
for entry in po2md.disabled_entries:
new_page._disabled_msgids.append(polib.unescape(entry.msgid))
new_page._translated_entries_msgstrs.append(entry.msgstr)
new_page._translated_entries_msgids.append(entry.msgid)

files.append(new_file)

Expand Down Expand Up @@ -596,8 +594,21 @@ def on_post_build(self, config):
if _entry_found:
po.remove(_entry_found)
po.save(page._po_filepath)

for entry in compendium_pofile:
if entry.msgid not in repeated_msgids:
entry.obsolete = True
compendium_pofile.save(compendium_filepath)

# mark not found msgstrs as obsolete
for page in pages:
po = polib.pofile(page._po_filepath)
for entry in po:
if entry.msgid not in page._translated_entries_msgids:
if entry.msgctxt != 'Page title':
entry.obsolete = True
po.save(page._po_filepath)

# reset mkdocs build instance
MkdocsBuild._instance = None

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = mkdocs_mdpo_plugin
version = 0.0.6
version = 0.0.5
description = Mkdocs plugin for translations using PO files.
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down

0 comments on commit 0a2987a

Please sign in to comment.