From 543cbe39b7d5bee47a69c6c62844b3cfa94faee0 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sat, 5 Jul 2025 19:14:42 +0100 Subject: [PATCH] Misc universal search improvements - Use zinc instead of gray - Translate all strings, and remove redundant ones - Add format, type and release year to record results - Use existing helpers instead of hand-rolled variants --- .../components/search_components.ex | 78 ++++++++++--------- priv/gettext/default.pot | 47 +++++++++++ priv/gettext/en/LC_MESSAGES/default.po | 47 +++++++++++ 3 files changed, 137 insertions(+), 35 deletions(-) diff --git a/lib/music_library_web/components/search_components.ex b/lib/music_library_web/components/search_components.ex index 7e211a86..2107248e 100644 --- a/lib/music_library_web/components/search_components.ex +++ b/lib/music_library_web/components/search_components.ex @@ -5,6 +5,8 @@ defmodule MusicLibraryWeb.SearchComponents do use MusicLibraryWeb, :html + import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1] + alias MusicLibrary.Records.Record @doc """ @@ -23,10 +25,10 @@ defmodule MusicLibraryWeb.SearchComponents do type="button" class={[ "flex items-center justify-center h-9 w-9 rounded-lg", - "text-gray-500 dark:text-gray-400", - "hover:text-gray-700 dark:hover:text-gray-300", - "hover:bg-gray-100 dark:hover:bg-gray-800", - "focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-gray-900", + "text-zinc-500 dark:text-zinc-400", + "hover:text-zinc-700 dark:hover:text-zinc-300", + "hover:bg-zinc-100 dark:hover:bg-zinc-800", + "focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-zinc-900", "transition-colors duration-200", @class ]} @@ -55,7 +57,7 @@ defmodule MusicLibraryWeb.SearchComponents do
-

+

{@record.title}

-

+

{Record.artist_names(@record)}

+

+ {format_label(@record.format)} · {type_label(@record.type)} · {Record.format_release_date( + @record.release_date + )} +

@@ -97,7 +104,7 @@ defmodule MusicLibraryWeb.SearchComponents do
-

+

{@artist.name}

-

+

{@artist.disambiguation}

@@ -147,11 +154,14 @@ defmodule MusicLibraryWeb.SearchComponents do def search_result_group(assigns) do ~H"""
-

- {@title} ({@count} +

+ {@title} @count}> - of <%= @total_count %> - ) + {gettext("(%{count} of %{total})", count: @count, total: @total_count)} + + + ({@count}) +

@@ -182,7 +192,7 @@ defmodule MusicLibraryWeb.SearchComponents do class="text-sm text-blue-600 dark:text-blue-400 hover:text-blue-800 dark:hover:text-blue-300 transition-colors" {@rest} > - View all {@count} {@target} results → + {gettext("View all %{count} %{target} results →", count: @count, target: @target)} """ end @@ -198,24 +208,24 @@ defmodule MusicLibraryWeb.SearchComponents do def keyboard_shortcuts(assigns) do ~H""" -
-
+
+
- ↑↓ - Navigate + ↑↓ + {gettext("Navigate")}
- - Select + + {gettext("Select")}
- Esc - Close + Esc + {gettext("Close")}
-
0} class="text-gray-500 dark:text-gray-400"> - {@total_results} results +
0} class="text-zinc-500 dark:text-zinc-400"> + {ngettext("1 result", "%{count} results", @total_results)}
@@ -232,11 +242,10 @@ defmodule MusicLibraryWeb.SearchComponents do def empty_state(assigns) do ~H"""
- <.icon name="hero-magnifying-glass" class="h-12 w-12 text-gray-400 mx-auto mb-4" /> -

Start typing to search your records and artists

-

- Use Ctrl+K - to open this search + <.icon name="hero-magnifying-glass" class="h-12 w-12 text-zinc-400 mx-auto mb-4" /> +

+ Ctrl+K + {gettext("to open this search")}

""" @@ -254,10 +263,9 @@ defmodule MusicLibraryWeb.SearchComponents do def no_results(assigns) do ~H"""
- <.icon name="hero-face-frown" class="h-12 w-12 text-gray-400 mx-auto mb-4" /> -

No results found for "{@query}"

-

- Try a different search term or check your spelling + <.icon name="hero-face-frown" class="h-12 w-12 text-zinc-400 mx-auto mb-4" /> +

+ {gettext("No results found for '%{query}'", query: @query)}

""" @@ -274,7 +282,7 @@ defmodule MusicLibraryWeb.SearchComponents do ~H"""
-

Searching...

+

{gettext("Searching...")}

""" end diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 8e58a6d6..29f5c368 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -1122,3 +1122,50 @@ msgstr "" #, elixir-autogen, elixir-format msgid "Enabled" msgstr "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format +msgid "No results found for '%{query}'" +msgstr "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format +msgid "Searching..." +msgstr "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format +msgid "View all %{count} %{target} results →" +msgstr "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format +msgid "(%{count} of %{total})" +msgstr "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format +msgid "1 result" +msgid_plural "%{count} results" +msgstr[0] "" +msgstr[1] "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format +msgid "Close" +msgstr "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format +msgid "Navigate" +msgstr "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format +msgid "Select" +msgstr "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format +msgid "to open this search" +msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index 55dd68f2..26068356 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -1122,3 +1122,50 @@ msgstr "" #, elixir-autogen, elixir-format, fuzzy msgid "Enabled" msgstr "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format +msgid "No results found for '%{query}'" +msgstr "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format, fuzzy +msgid "Searching..." +msgstr "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format +msgid "View all %{count} %{target} results →" +msgstr "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format +msgid "(%{count} of %{total})" +msgstr "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format, fuzzy +msgid "1 result" +msgid_plural "%{count} results" +msgstr[0] "" +msgstr[1] "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format +msgid "Close" +msgstr "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format +msgid "Navigate" +msgstr "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format +msgid "Select" +msgstr "" + +#: lib/music_library_web/components/search_components.ex +#, elixir-autogen, elixir-format +msgid "to open this search" +msgstr ""