Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/lingva/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -124,10 +124,9 @@ 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
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
Expand Down Expand Up @@ -267,6 +266,7 @@ def extract(
linenumbers=True,
width=79,
sort_order=None,
allow_empty=False,
domain=None,
keywords=None,
comment_tag=None,
Expand All @@ -276,7 +276,6 @@ def extract(
msgid_bugs_address=None,
):
"""Extract translatable strings."""
directory = list(directory)
register_extractors()
register_babel_plugins()

Expand All @@ -300,6 +299,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:
Expand Down Expand Up @@ -329,7 +330,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)

Expand Down Expand Up @@ -407,6 +408,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(
Expand Down Expand Up @@ -454,6 +461,7 @@ def main(
linenumbers,
width,
sort_order,
allow_empty,
domain,
keywords,
comment_tag,
Expand All @@ -474,6 +482,7 @@ def main(
linenumbers,
width,
sort_order,
allow_empty,
domain,
keywords,
comment_tag,
Expand Down