diff --git a/wagtail_localize/templates/wagtail_localize/icons/wagtail-localize-language.svg b/wagtail_localize/templates/wagtail_localize/icons/wagtail-localize-language.svg new file mode 100644 index 00000000..40826b1e --- /dev/null +++ b/wagtail_localize/templates/wagtail_localize/icons/wagtail-localize-language.svg @@ -0,0 +1,2 @@ + + diff --git a/wagtail_localize/wagtail_hooks.py b/wagtail_localize/wagtail_hooks.py index fc276b1e..e3b62498 100644 --- a/wagtail_localize/wagtail_hooks.py +++ b/wagtail_localize/wagtail_hooks.py @@ -134,6 +134,18 @@ def register_submit_translation_permission(): ) +if WAGTAIL_VERSION >= (4, 0, 0): + + def set_button_icon(button, icon_name): + button.icon_name = icon_name + return button + +else: + + def set_button_icon(button, icon_name): + return button + + def page_listing_more_buttons(page, page_perms, next_url=None): if not page.is_root() and page_perms.user.has_perm( "wagtail_localize.submit_translation" @@ -148,8 +160,9 @@ def page_listing_more_buttons(page, page_perms, next_url=None): if has_locale_to_translate_to: url = reverse("wagtail_localize:submit_page_translation", args=[page.id]) - yield wagtailadmin_widgets.Button( - _("Translate this page"), url, priority=60 + yield set_button_icon( + wagtailadmin_widgets.Button(_("Translate this page"), url, priority=60), + "wagtail-localize-language", ) # If the page is the source for translations, show "Sync translated pages" button @@ -159,20 +172,24 @@ def page_listing_more_buttons(page, page_perms, next_url=None): if next_url is not None: url += "?" + urlencode({"next": next_url}) - yield wagtailadmin_widgets.Button( - _("Sync translated pages"), url, priority=65 + yield set_button_icon( + wagtailadmin_widgets.Button( + _("Sync translated pages"), url, priority=65 + ), + "resubmit", ) if WAGTAIL_VERSION >= (4, 0, 0): - @hooks.register("register_page_listing_more_buttons") - def register_page_listing_more_buttons(page, page_perms, next_url=None): - for button in page_listing_more_buttons(page, page_perms, next_url): - yield button + hooks.register("register_page_header_buttons", page_listing_more_buttons) + hooks.register("register_page_listing_more_buttons", page_listing_more_buttons) else: + if WAGTAIL_VERSION >= (2, 16, 0): + hooks.register("register_page_header_buttons", page_listing_more_buttons) + @hooks.register("register_page_listing_more_buttons") def register_page_listing_more_buttons( page, page_perms, is_parent=False, next_url=None @@ -413,5 +430,9 @@ def format_message(self, log_entry): @hooks.register("register_icons") def register_icons(icons): - # icon id "wagtail-localize-convert" (which translates to `.icon-wagtail-localize-convert`) - return icons + ["wagtail_localize/icons/wagtail-localize-convert.svg"] + return icons + [ + # icon id "wagtail-localize-convert" (which translates to `.icon-wagtail-localize-convert`) + "wagtail_localize/icons/wagtail-localize-convert.svg", + # icon id "wagtail-localize-language" (which translates to `.icon-wagtail-localize-language`) + "wagtail_localize/icons/wagtail-localize-language.svg", + ]