From 9db3bbabe5688a35315adaa0d9a4dcbe813a3481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 7 Nov 2024 10:15:27 +0100 Subject: [PATCH] feat: Offer bilingual configuration for CSV --- CHANGES.rst | 1 + translation_finder/discovery/files.py | 12 +++++++++++- translation_finder/test_discovery.py | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 73ffbca..0baecab 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,6 +6,7 @@ Changelog * Not yet released. * Added support for Format.JS files. +* Offer bilingual configuration for CSV. 2.16 ---- diff --git a/translation_finder/discovery/files.py b/translation_finder/discovery/files.py index 426937a..7ca6fcd 100644 --- a/translation_finder/discovery/files.py +++ b/translation_finder/discovery/files.py @@ -27,7 +27,7 @@ class GettextDiscovery(BaseDiscovery): new_base_mask = "*.pot" def discover(self, eager: bool = False, hint: Optional[str] = None): - for result in super().discover(eager=eager): + for result in super().discover(eager=eager, hint=hint): if "template" not in result: yield result continue @@ -101,6 +101,16 @@ class CSVDiscovery(MonoTemplateDiscovery): file_format = "csv" mask = "*.csv" + def discover(self, eager: bool = False, hint: Optional[str] = None): + for result in super().discover(eager=eager, hint=hint): + if "template" not in result: + yield result + continue + bilingual = result.copy() + del bilingual["template"] + yield bilingual + yield result + @register_discovery class WebExtensionDiscovery(BaseDiscovery): diff --git a/translation_finder/test_discovery.py b/translation_finder/test_discovery.py index 1a0ca40..df4e27b 100644 --- a/translation_finder/test_discovery.py +++ b/translation_finder/test_discovery.py @@ -1272,6 +1272,11 @@ def test_basic(self): self.assert_discovery( discovery.discover(), [ + { + "filemask": "csv/*.csv", + "file_format": "csv", + "new_base": "csv/en.csv", + }, { "filemask": "csv/*.csv", "file_format": "csv",