From 57535687eb32dd8b3ed7ffd59e634f07c50c40be Mon Sep 17 00:00:00 2001 From: "Jules Lasne (jlasne - seluj78)" Date: Fri, 13 Dec 2019 15:31:01 +0100 Subject: [PATCH 1/3] Removing obsolete entries from fuzzies #16 --- potodo/_po_file.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/potodo/_po_file.py b/potodo/_po_file.py index 9a85566..608ff22 100644 --- a/potodo/_po_file.py +++ b/potodo/_po_file.py @@ -1,4 +1,4 @@ -from typing import Dict, Mapping, Sequence, Set +from typing import Dict, Mapping, Sequence, Set, List from pathlib import Path import polib @@ -16,9 +16,17 @@ class PoFileStats: self.pofile: polib.POFile = polib.pofile(self.path) self.directory: str = self.path.parent.name - self.fuzzy_entries: Sequence[polib.POEntry] = self.pofile.fuzzy_entries() + self.obsolete_entries: Sequence[polib.POEntry] = self.pofile.obsolete_entries() + self.obsolete_nb: int = len(self.pofile.obsolete_entries()) + + self.fuzzy_entries: List[polib.POEntry] = self.pofile.fuzzy_entries() self.fuzzy_nb: int = len(self.fuzzy_entries) + for entry in self.obsolete_entries: + if entry.fuzzy: + self.fuzzy_nb -= 1 + self.fuzzy_entries.remove(entry) + self.percent_translated: int = self.pofile.percent_translated() self.translated_entries: Sequence[ @@ -30,10 +38,6 @@ class PoFileStats: polib.POEntry ] = self.pofile.untranslated_entries() self.untranslated_nb: int = len(self.untranslated_entries) - - self.obsolete_entries: Sequence[polib.POEntry] = self.pofile.obsolete_entries() - self.obsolete_nb: int = len(self.pofile.obsolete_entries()) - self.po_file_size = len(self.pofile) - self.obsolete_nb self.filename_dir: str = self.directory + "/" + self.filename From a1261f7141492b78e7e53ac804b96f7ec05bc4af Mon Sep 17 00:00:00 2001 From: "Jules Lasne (jlasne - seluj78)" Date: Fri, 13 Dec 2019 16:54:54 +0100 Subject: [PATCH 2/3] Added suggestion from @JulienPalard --- potodo/_po_file.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/potodo/_po_file.py b/potodo/_po_file.py index 608ff22..c35247b 100644 --- a/potodo/_po_file.py +++ b/potodo/_po_file.py @@ -19,16 +19,11 @@ class PoFileStats: self.obsolete_entries: Sequence[polib.POEntry] = self.pofile.obsolete_entries() self.obsolete_nb: int = len(self.pofile.obsolete_entries()) - self.fuzzy_entries: List[polib.POEntry] = self.pofile.fuzzy_entries() + self.fuzzy_entries: List[polib.POEntry] = [ + entry for entry in self.pofile if entry.fuzzy and not entry.obsolete + ] self.fuzzy_nb: int = len(self.fuzzy_entries) - for entry in self.obsolete_entries: - if entry.fuzzy: - self.fuzzy_nb -= 1 - self.fuzzy_entries.remove(entry) - - self.percent_translated: int = self.pofile.percent_translated() - self.translated_entries: Sequence[ polib.POEntry ] = self.pofile.translated_entries() @@ -38,8 +33,9 @@ class PoFileStats: polib.POEntry ] = self.pofile.untranslated_entries() self.untranslated_nb: int = len(self.untranslated_entries) - self.po_file_size = len(self.pofile) - self.obsolete_nb + self.percent_translated: int = self.pofile.percent_translated() + self.po_file_size = len(self.pofile) - self.obsolete_nb self.filename_dir: str = self.directory + "/" + self.filename def __str__(self) -> str: From 7e20819c0699dc29a5c6ddc6abc365c40345cfc1 Mon Sep 17 00:00:00 2001 From: "Jules Lasne (jlasne - seluj78)" Date: Fri, 13 Dec 2019 17:39:31 +0100 Subject: [PATCH 3/3] Added obsolete test --- tests/fixtures/python-docs-fr/obsolete.po | 39 +++++++++++++++++++++++ tests/test_potodo.py | 2 ++ 2 files changed, 41 insertions(+) create mode 100644 tests/fixtures/python-docs-fr/obsolete.po diff --git a/tests/fixtures/python-docs-fr/obsolete.po b/tests/fixtures/python-docs-fr/obsolete.po new file mode 100644 index 0000000..8333b57 --- /dev/null +++ b/tests/fixtures/python-docs-fr/obsolete.po @@ -0,0 +1,39 @@ +msgid "" +msgstr "" +"Project-Id-Version: Python 3\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-10-09 17:54+0200\n" +"PO-Revision-Date: 2019-11-02 14:46+0100\n" +"Last-Translator: XXX\n" +"Language-Team: FRENCH \n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.2.1\n" + +#: /un/chemin/idiot.rst:69 +msgid "This is a dummy sentence." +msgstr "Ceci est une phrase bateau." + +#: /un/chemin/idiot.rst:420 +msgid "Incredibly useful as a tool, this potodo" +msgstr "Incroyablement utile comme outil, ce potodo" + +#: /un/chemin/idiot.rst:666 +msgid "We should translate this eventually" +msgstr "" + +#~ msgid "Supported Versions" +#~ msgstr "Versions supportées" + +#~ msgid "Other resources" +#~ msgstr "Autres ressources" + +#, fuzzy +#~ msgid "MingW -- Python extensions" +#~ msgstr "Utiliser Python sur Windows" + +#, fuzzy +#~ msgid "A Python for Windows Tutorial" +#~ msgstr "Utiliser Python sur Windows" diff --git a/tests/test_potodo.py b/tests/test_potodo.py index d4ba2a8..722486b 100644 --- a/tests/test_potodo.py +++ b/tests/test_potodo.py @@ -22,3 +22,5 @@ def test_potodo(capsys): assert "token.po" in captured.out assert "glossary.po" not in captured.out assert "sphinx.po" not in captured.out + assert "2 fuzzy" not in captured.out + assert "3 fuzzy" in captured.out