From 39edf1a58dce51115baa82edd94cbfb591710863 Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Tue, 11 Feb 2025 13:25:34 +0200 Subject: [PATCH 1/3] Fix `directory` parameter handling --- src/lingva/extract.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lingva/extract.py b/src/lingva/extract.py index 6292aaf..6887639 100644 --- a/src/lingva/extract.py +++ b/src/lingva/extract.py @@ -78,7 +78,7 @@ def update(self, message, add_occurrences=True): class POFile(polib.POFile): - copyright = None + copyright_holder = None package_name = None def metadata_as_entry(self): @@ -124,9 +124,11 @@ def list_files(files_from, sources): sys.exit(1) -def find_file(filename, search_path=[]): +def find_file(filename, search_path=None): """Return the filename for a given file, checking search paths.""" - paths = [os.path.curdir] + search_path + if search_path is None: + search_path = [] + paths = (os.path.curdir, *search_path) for path in paths: filename = os.path.join(path, filename) if os.path.isfile(filename): @@ -276,7 +278,6 @@ def extract( msgid_bugs_address=None, ): """Extract translatable strings.""" - directory = list(directory) register_extractors() register_babel_plugins() @@ -300,6 +301,8 @@ def extract( ) scanned = 0 + if directory and not isinstance(directory, list): + directory = list(directory) for filename in no_duplicates(list_files(files_from, sources)): real_filename = find_file(filename, directory) if real_filename is None: From de7fffb9617643bb0489e5a76013eeb5afc64b7e Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Thu, 10 Apr 2025 21:23:16 +0300 Subject: [PATCH 2/3] Add `--allow-empty` parameter --- src/lingva/extract.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lingva/extract.py b/src/lingva/extract.py index 6887639..0efa558 100644 --- a/src/lingva/extract.py +++ b/src/lingva/extract.py @@ -269,6 +269,7 @@ def extract( linenumbers=True, width=79, sort_order=None, + allow_empty=False, domain=None, keywords=None, comment_tag=None, @@ -332,7 +333,7 @@ def extract( if not scanned: click.echo("No files scanned, aborting", err=True) sys.exit(1) - if not catalog: + if not catalog and not allow_empty: click.echo("No translatable strings found, aborting", err=True) sys.exit(2) @@ -410,6 +411,12 @@ def extract( flag_value="location", help="Order messages by file location", ) +@click.option( + "--allow-empty", + "allow_empty", + default=False, + help="Allow output file with no msg entries", +) # Extraction configuration @click.option("-d", "--domain", help="Domain to extract") @click.option( @@ -457,6 +464,7 @@ def main( linenumbers, width, sort_order, + allow_empty, domain, keywords, comment_tag, @@ -477,6 +485,7 @@ def main( linenumbers, width, sort_order, + allow_empty, domain, keywords, comment_tag, From 34d733ae55de4c9c7944740b084b7141963cc35b Mon Sep 17 00:00:00 2001 From: ~Jhellico Date: Tue, 15 Apr 2025 01:07:36 +0300 Subject: [PATCH 3/3] PR suggestion --- src/lingva/extract.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/lingva/extract.py b/src/lingva/extract.py index 0efa558..9e473eb 100644 --- a/src/lingva/extract.py +++ b/src/lingva/extract.py @@ -126,10 +126,7 @@ def list_files(files_from, sources): def find_file(filename, search_path=None): """Return the filename for a given file, checking search paths.""" - if search_path is None: - search_path = [] - paths = (os.path.curdir, *search_path) - for path in paths: + for path in (os.path.curdir, *(search_path or ())): filename = os.path.join(path, filename) if os.path.isfile(filename): return filename