Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove extra checks from extract_messages #9442

Merged
Show file tree
Hide file tree
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
24 changes: 6 additions & 18 deletions openlibrary/i18n/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ def extract_templetor(fileobj, keywords, comment_tags, options):
return extract_python(f, keywords, comment_tags, options)


def extract_messages(
dirs: list[str], verbose: bool, forced: bool, skip_untracked: bool
):
def extract_messages(dirs: list[str], verbose: bool, skip_untracked: bool):
# The creation date is fixed to prevent merge conflicts on this line as a result of i18n auto-updates
# In the unlikely event we need to update the fixed creation date, you can change the hard-coded date below
fixed_creation_date = datetime.fromisoformat('2024-05-01 18:58-0400')
Expand All @@ -173,9 +171,6 @@ def extract_messages(
METHODS = [("**.py", "python"), ("**.html", "openlibrary.i18n:extract_templetor")]
COMMENT_TAGS = ["NOTE:"]

template = read_po((Path(root) / 'messages.pot').open('rb'))
msg_set = {msg.id for msg in template if msg.id != ''}
new_set = set()
skipped_files = set()
if skip_untracked:
skipped_files = get_untracked_files(dirs, ('.py', '.html'))
Expand All @@ -190,7 +185,6 @@ def extract_messages(
file_path = Path(d) / filename
if file_path in skipped_files:
continue
new_set.add(message)
counts[filename] = counts.get(filename, 0) + 1
catalog.add(message, None, [(filename, lineno)], auto_comments=comments)

Expand All @@ -199,18 +193,12 @@ def extract_messages(
path = filename if d == filename else os.path.join(d, filename)
print(f"{count}\t{path}", file=sys.stderr)

has_changed = msg_set != new_set
if has_changed or forced:
path = os.path.join(root, 'messages.pot')
f = open(path, 'wb')
write_po(f, catalog, include_lineno=False)
f.close()
path = os.path.join(root, 'messages.pot')
f = open(path, 'wb')
write_po(f, catalog, include_lineno=False)
f.close()

print('Updated strings written to', path)
else:
print(
'No modified strings discovered. To force a template update, re-run with --force-write.'
)
print('Updated strings written to', path)


def compile_translations(locales: list[str]):
Expand Down
7 changes: 3 additions & 4 deletions openlibrary/i18n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,8 @@ msgstr ""

#: authors/index.html lib/nav_head.html lists/home.html
#: publishers/notfound.html publishers/view.html search/advancedsearch.html
#: search/authors.html search/inside.html search/lists.html
#: search/publishers.html search/subjects.html subjects.html
#: subjects/notfound.html type/local_id/view.html work_search.html
#: search/publishers.html search/searchbox.html subjects.html
#: subjects/notfound.html type/local_id/view.html
msgid "Search"
msgstr ""

Expand Down Expand Up @@ -4392,7 +4391,7 @@ msgstr ""
msgid "Recent Activity"
msgstr ""

#: lists/home.html
#: lists/home.html lists/showcase.html
msgid "See all"
msgstr ""

Expand Down
1 change: 0 additions & 1 deletion scripts/i18n-messages
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def main(cmd, args):
i18n.extract_messages(
message_sources,
verbose='--verbose' in args,
forced='--force-write' in args,
skip_untracked='--skip-untracked' in args,
)
elif cmd == 'compile':
Expand Down
Loading