Skip to content

Commit

Permalink
Merge pull request #9502 from rebecca-shoptaw/9486/fix/update-warn-re…
Browse files Browse the repository at this point in the history
…gex-and-escape-python

Update `i18n` warn regex and escape relevant files
  • Loading branch information
mekarpeles authored Jul 1, 2024
2 parents 5ae246f + e0424da commit 19ebfad
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
12 changes: 11 additions & 1 deletion openlibrary/i18n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5474,7 +5474,7 @@ msgid ""
"href=\"%(url)s\">everything</a> by this author?"
msgstr ""

#: type/author/view.html
#: Profile.html type/author/view.html
msgid "Time"
msgstr ""

Expand Down Expand Up @@ -6083,6 +6083,12 @@ msgstr ""
msgid "Preview Book"
msgstr ""

#: DisplayCode.html
msgid ""
"Templates in the website are disabled now. Editing them will not have any"
" effect on the live website."
msgstr ""

#: DonateModal.html
msgid ""
"Donate this book to the <a href=\"https://archive.org\">Internet "
Expand Down Expand Up @@ -6257,6 +6263,10 @@ msgstr ""
msgid "First"
msgstr ""

#: Profile.html
msgid "Component"
msgstr ""

#: ReadButton.html
msgid "Special Access"
msgstr ""
Expand Down
3 changes: 2 additions & 1 deletion openlibrary/macros/DisplayCode.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<tr>
<td>
<pre>\
$# detect-missing-i18n-skip-line
$for i in range(n): <span rel="#L$(i+1)">$("%4d" % (i+1))</span>
</pre>
</td>
Expand All @@ -20,7 +21,7 @@
</table>

<div class="contenttext">
<div class="red" style="background-color: white; padding: 20px;">Templates in the website are disabled now. Editing them will not have any effect on the live website.</div>
<div class="red" style="background-color: white; padding: 20px;">$_("Templates in the website are disabled now. Editing them will not have any effect on the live website.")</div>

$:splitlines(code)
</div>
6 changes: 4 additions & 2 deletions openlibrary/macros/Profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
<table>
<thead>
<tr>
<th>Component</th>
<th>Time</th>
<th>$_("Component")</th>
<th>$_("Time")</th>
<th>%</th>
</tr>
</thead>
<tbody>
$for component in sorted(component_times.items(), key=lambda x: x[1]):
<tr>
<td>$component[0]</td>
$# detect-missing-i18n-skip-line
<td>$("%.2f" % component[1])</td>
$# detect-missing-i18n-skip-line
<td>$("%.2f" % (component[1] / component_times['TotalTime'] * 100.))</td>
</tr>
</tbody>
Expand Down
2 changes: 2 additions & 0 deletions openlibrary/templates/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ <h2>$_("Edits")</h2>
<td class="type">$_("Total")</td>
<td class="amount">$commify(counts.bot_edits.latest + counts.human_edits.latest)</td>
<td class="amount">$commify(counts.bot_edits.previous + counts.human_edits.previous)</td>
$# detect-missing-i18n-skip-line
<td class="amount">$commify(counts.bot_edits.get_summary(7) + counts.human_edits.get_summary(7))</td>
$# detect-missing-i18n-skip-line
<td class="amount">$commify(counts.bot_edits.get_summary(28) + counts.human_edits.get_summary(28))</td>
</tr>
</tbody>
Expand Down
25 changes: 7 additions & 18 deletions scripts/detect_missing_i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
# This is a list of files that had pre-existing i18n errors/warnings at the time this script was created.
# Chip away at these and remove them from the exclude list (except where otherwise noted).
EXCLUDE_LIST = {
"openlibrary/admin/templates/admin/index.html",
"openlibrary/templates/design.html",
"openlibrary/templates/diff.html",
"openlibrary/templates/internalerror.html",
"openlibrary/templates/login.html",
"openlibrary/templates/permission_denied.html",
Expand All @@ -23,18 +21,15 @@
"openlibrary/templates/showia.html",
"openlibrary/templates/subjects.html",
"openlibrary/templates/about/index.html",
"openlibrary/templates/account/create.html",
"openlibrary/templates/account/import.html",
"openlibrary/templates/account/readinglog_stats.html",
"openlibrary/templates/account/email/forgot.html",
"openlibrary/templates/account/sidebar.html",
"openlibrary/templates/admin/attach_debugger.html",
"openlibrary/templates/admin/block.html",
"openlibrary/templates/admin/graphs.html",
"openlibrary/templates/admin/history.html",
"openlibrary/templates/admin/imports.html",
"openlibrary/templates/admin/imports_by_date.html",
"openlibrary/templates/admin/index.html",
"openlibrary/templates/admin/loans.html",
"openlibrary/templates/admin/loans_table.html",
"openlibrary/templates/admin/solr.html",
Expand All @@ -50,16 +45,13 @@
"openlibrary/templates/admin/people/view.html",
"openlibrary/templates/books/add.html",
"openlibrary/templates/books/custom_carousel.html",
"openlibrary/templates/books/edit.html",
"openlibrary/templates/books/mobile_carousel.html",
"openlibrary/templates/books/works-show.html",
"openlibrary/templates/books/edit/edition.html",
"openlibrary/templates/books/edit/web.html",
"openlibrary/templates/check_ins/check_in_form.html",
"openlibrary/templates/contact/spam/sent.html",
"openlibrary/templates/covers/add.html",
"openlibrary/templates/email/case_created.html",
"openlibrary/templates/history/sources.html",
"openlibrary/templates/home/loans.html",
"openlibrary/templates/home/popular.html",
"openlibrary/templates/home/returncart.html",
Expand All @@ -68,11 +60,9 @@
"openlibrary/templates/languages/index.html",
"openlibrary/templates/languages/language_list.html",
"openlibrary/templates/lib/history.html",
"openlibrary/templates/lib/header_dropdown.html",
"openlibrary/templates/lib/nav_foot.html",
"openlibrary/templates/lists/export_as_html.html",
"openlibrary/templates/lists/feed_updates.html",
"openlibrary/templates/lists/list_overview.html",
"openlibrary/templates/lists/widget.html",
"openlibrary/templates/my_books/dropdown_content.html",
"openlibrary/templates/my_books/primary_action.html",
Expand All @@ -88,7 +78,6 @@
"openlibrary/templates/recentchanges/merge/path.html",
"openlibrary/templates/recentchanges/undo/view.html",
"openlibrary/templates/search/snippets.html",
"openlibrary/templates/search/work_search_facets.html",
"openlibrary/templates/site/alert.html",
"openlibrary/templates/site/stats.html",
"openlibrary/templates/type/about/view.html",
Expand All @@ -100,21 +89,16 @@
"openlibrary/templates/type/list/edit.html",
"openlibrary/templates/type/list/exports.html",
"openlibrary/templates/type/local_id/view.html",
"openlibrary/templates/type/object/view.html",
"openlibrary/templates/type/page/view.html",
"openlibrary/templates/type/template/edit.html",
"openlibrary/templates/type/template/view.html",
"openlibrary/templates/type/type/view.html",
"openlibrary/templates/type/work/editions_datatable.html",
"openlibrary/templates/type/work/view.html",
"openlibrary/macros/databarView.html",
"openlibrary/macros/DisplayCode.html",
"openlibrary/macros/FulltextSnippet.html",
"openlibrary/macros/IABook.html",
"openlibrary/macros/ManageLoansButtons.html",
"openlibrary/macros/ManageWaitlistButton.html",
"openlibrary/macros/NotesModal.html",
"openlibrary/macros/Profile.html",
"openlibrary/macros/QueryCarousel.html",
"openlibrary/macros/RecentChangesAdmin.html",
"openlibrary/macros/RecentChangesUsers.html",
Expand All @@ -123,6 +107,11 @@
"openlibrary/macros/WorldcatLink.html",
"openlibrary/macros/databarWork.html",
"openlibrary/macros/WorkInfo.html",
# These are excluded because they require more info to fix
"openlibrary/templates/books/edit.html",
"openlibrary/templates/history/sources.html",
# This can't be fixed because it's not in the i18n directories
"openlibrary/admin/templates/admin/index.html",
# These can't be fixed since they're rendered as static html
"static/offline.html",
"static/status-500.html",
Expand Down Expand Up @@ -166,7 +155,7 @@ class Errtype(str, Enum):
)

i18n_element_missing_regex = opening_tag_syntax + ignore_after_opening_tag
i18n_element_warn_regex = opening_tag_syntax + r"\$\((?!_\()"
i18n_element_warn_regex = opening_tag_syntax + r"\$\(['\"]"

attr_syntax = r"(title|placeholder|alt)="
ignore_double_quote = (
Expand Down Expand Up @@ -197,7 +186,7 @@ class Errtype(str, Enum):
+ ignore_single_quote
+ r")[^>]*?>"
)
i18n_attr_warn_regex = opening_tag_open + attr_syntax + r"['\"]\$\((?!_\()"
i18n_attr_warn_regex = opening_tag_open + attr_syntax + r"\"\$\(\'"


def terminal_underline(text: str) -> str:
Expand Down

0 comments on commit 19ebfad

Please sign in to comment.