Skip to content

Commit

Permalink
Minor change
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja committed Feb 27, 2022
1 parent fb3b0f7 commit 4472a57
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
22 changes: 0 additions & 22 deletions mkdocs_mdpo_plugin/mdpo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,3 @@ def remove_mdpo_commands_preserving_escaped(text):
),
),
)


def po_messages_stats(pofile_content):
untranslated_messages, total_messages = -1, -1
content_lines = pofile_content.splitlines()

for i, line in enumerate(content_lines):
next_i = i + 1

if line.startswith('msgid "'):
total_messages += 1

if line.startswith('msgstr ""') and (
next_i == len(content_lines) or (not content_lines[next_i].strip())
):
untranslated_messages += 1

return (
total_messages - untranslated_messages,
total_messages,
# (total_messages - untranslated_messages) / total_messages * 100,
)
7 changes: 5 additions & 2 deletions mkdocs_mdpo_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
build_po2md_events,
)
from mkdocs_mdpo_plugin.mdpo_utils import (
po_messages_stats,
remove_mdpo_commands_preserving_escaped,
)
from mkdocs_mdpo_plugin.mkdocs_utils import (
Expand All @@ -27,7 +26,11 @@
)
from mkdocs_mdpo_plugin.search_indexes import TranslationsSearchPatcher
from mkdocs_mdpo_plugin.translations import Translation, Translations
from mkdocs_mdpo_plugin.utils import readable_float, removesuffix
from mkdocs_mdpo_plugin.utils import (
po_messages_stats,
readable_float,
removesuffix,
)


class MdpoPlugin(mkdocs.plugins.BasePlugin):
Expand Down
21 changes: 21 additions & 0 deletions mkdocs_mdpo_plugin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,24 @@ def removesuffix(s, suf):
if suf and s.endswith(suf):
return s[:-len(suf)]
return s


def po_messages_stats(pofile_content):
untranslated_messages, total_messages = -1, -1
content_lines = pofile_content.splitlines()

for i, line in enumerate(content_lines):
next_i = i + 1

if line.startswith('msgid "'):
total_messages += 1

if line.startswith('msgstr ""') and (
next_i == len(content_lines) or (not content_lines[next_i].strip())
):
untranslated_messages += 1

return (
total_messages - untranslated_messages,
total_messages,
)

0 comments on commit 4472a57

Please sign in to comment.