Refactor type/format labels to enable translations

This commit is contained in:
Claudio Ortolina
2025-01-29 11:04:19 +00:00
parent 96bd453900
commit 9e1f00c9a8
16 changed files with 193 additions and 132 deletions
@@ -1,6 +1,7 @@
defmodule MusicLibraryWeb.ArtistLive.RecordComponents do
use MusicLibraryWeb, :live_component
import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1]
alias MusicLibrary.Records
attr :records, :list, required: true
@@ -46,9 +47,7 @@ defmodule MusicLibraryWeb.ArtistLive.RecordComponents do
{record.title}
</p>
<p class="pointer-events-none block text-sm font-medium text-zinc-500">
{Records.Record.format_long_label(record.format)} · {Records.Record.type_long_label(
record.type
)}
{format_label(record.format)} · {type_label(record.type)}
</p>
<p class="pointer-events-none block text-sm font-medium text-zinc-500">
{Records.Record.format_release(record.release)}
@@ -1,7 +1,9 @@
defmodule MusicLibraryWeb.CollectionLive.Show do
use MusicLibraryWeb, :live_view
import MusicLibraryWeb.RecordComponents, only: [toggle_actions_menu: 1, close_actions_menu: 1]
import MusicLibraryWeb.RecordComponents,
only: [toggle_actions_menu: 1, close_actions_menu: 1, format_label: 1, type_label: 1]
alias Phoenix.LiveView.JS
alias MusicLibrary.Records
@@ -22,9 +22,9 @@
{@record.title}
</h2>
<p class="mt-2 text-sm leading-5 text-zinc-500 dark:text-zinc-400">
{Records.Record.format_release(@record.release)} · {Records.Record.format_long_label(
@record.format
)} · {Records.Record.type_long_label(@record.type)}
{Records.Record.format_release(@record.release)} · {format_label(@record.format)} · {type_label(
@record.type
)}
</p>
</div>
<div class="relative flex-none">
@@ -1,6 +1,7 @@
defmodule MusicLibraryWeb.RecordLive.FormComponent do
use MusicLibraryWeb, :live_component
import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1]
alias MusicLibrary.Records
alias MusicLibrary.Records.Cover
@@ -37,14 +38,14 @@ defmodule MusicLibraryWeb.RecordLive.FormComponent do
type="select"
label={gettext("Type")}
prompt={gettext("Choose a value")}
options={Records.Record.types_with_labels()}
options={types_with_labels()}
/>
<.input
field={@form[:format]}
type="select"
label={gettext("Format")}
prompt={gettext("Choose a value")}
options={Records.Record.formats_with_labels()}
options={formats_with_labels()}
/>
</div>
<.input field={@form[:musicbrainz_id]} type="text" label={gettext("MusicBrainz ID")} />
@@ -132,5 +133,13 @@ defmodule MusicLibraryWeb.RecordLive.FormComponent do
end
end
def formats_with_labels do
Enum.map(Records.Record.formats(), fn f -> {format_label(f), f} end)
end
def types_with_labels do
Enum.map(Records.Record.types(), fn t -> {type_label(t), t} end)
end
defp notify_parent(msg), do: send(self(), {__MODULE__, msg})
end
@@ -1,7 +1,9 @@
defmodule MusicLibraryWeb.RecordLive.ImportComponent do
use MusicLibraryWeb, :live_component
import MusicLibraryWeb.RecordComponents, only: [toggle_actions_menu: 1, close_actions_menu: 1]
import MusicLibraryWeb.RecordComponents,
only: [toggle_actions_menu: 1, close_actions_menu: 1, format_label: 1, type_label: 1]
alias MusicLibrary.Records
@impl true
@@ -68,9 +70,7 @@ defmodule MusicLibraryWeb.RecordLive.ImportComponent do
{@release_group.title}
</h2>
<p class="mt-1 text-xs leading-5 text-zinc-500 dark:text-zinc-400">
{Records.Record.format_release(@release_group.release)} · {Records.Record.type_long_label(
@release_group.type
)}
{Records.Record.format_release(@release_group.release)} · {type_label(@release_group.type)}
</p>
</div>
<div class="relative flex-none">
@@ -115,7 +115,7 @@ defmodule MusicLibraryWeb.RecordLive.ImportComponent do
JS.push("import", value: %{id: @release_group.id, format: format}, page_loading: true)
}
>
{Records.Record.format_long_label(format)}
{format_label(format)}
</.link>
</.focus_wrap>
</div>
@@ -2,9 +2,9 @@ defmodule MusicLibraryWeb.StatsLive.Index do
use MusicLibraryWeb, :live_view
import MusicLibraryWeb.StatsLive.DataComponents
import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1]
alias MusicLibrary.{Artists, Collection, Records, Wishlist}
alias Records.Record
def mount(_params, _session, socket) do
latest_record = Collection.get_latest_record!()
@@ -29,7 +29,7 @@
]}>
<div :for={{format, count} <- @collection_count_by_format} class="px-2 py-5 sm:px-4">
<dt class="text-sm font-medium text-zinc-500 dark:text-zinc-400 text-center max-sm:text-xs break-keep">
{Record.format_long_label(format)}
{format_label(format)}
</dt>
<dd class="mt-1 text-center">
<.link
@@ -54,7 +54,7 @@
]}>
<div :for={{type, count} <- @collection_count_by_type} class="px-2 py-5 sm:px-4">
<dt class="text-sm font-medium text-zinc-500 dark:text-zinc-400 text-center max-sm:text-xs break-keep">
{Record.type_long_label(type)}
{type_label(type)}
</dt>
<dd class="mt-1 text-center">
<.link
@@ -202,7 +202,7 @@
)
}
>
{Records.Record.format_long_label(format)}
{format_label(format)}
</.link>
</.focus_wrap>
</div>
@@ -1,7 +1,9 @@
defmodule MusicLibraryWeb.WishlistLive.Show do
use MusicLibraryWeb, :live_view
import MusicLibraryWeb.RecordComponents, only: [toggle_actions_menu: 1, close_actions_menu: 1]
import MusicLibraryWeb.RecordComponents,
only: [toggle_actions_menu: 1, close_actions_menu: 1, format_label: 1, type_label: 1]
alias MusicLibrary.Records
@impl true
@@ -26,9 +26,7 @@
<span :if={@current_date && !Records.Record.released?(@record, @current_date)}>
({gettext("Unreleased")})
</span>
· {Records.Record.format_long_label(@record.format)} · {Records.Record.type_long_label(
@record.type
)}
· {format_label(@record.format)} · {type_label(@record.type)}
</p>
</div>
<div class="relative flex-none">