From 07fe6e693253d00de055178d0a48d318cc602eda Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Thu, 19 Mar 2026 12:14:50 -0500 Subject: [PATCH] fix/subscriber-count-pluralization (#84) Reviewed-on: https://git.mcintire.me/graham/towerops-web/pulls/84 --- lib/towerops_web/live/dashboard_live.ex | 6 ++++++ lib/towerops_web/live/dashboard_live.html.heex | 2 +- lib/towerops_web/live/device_live/index.ex | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/towerops_web/live/dashboard_live.ex b/lib/towerops_web/live/dashboard_live.ex index a7b73ac2..d18667b3 100644 --- a/lib/towerops_web/live/dashboard_live.ex +++ b/lib/towerops_web/live/dashboard_live.ex @@ -287,6 +287,12 @@ defmodule ToweropsWeb.DashboardLive do defp format_number(number), do: to_string(number) + defp format_subscriber_count(count) when is_float(count), do: format_subscriber_count(round(count)) + + defp format_subscriber_count(count) when is_integer(count) and count > 0 do + ngettext("%{count} sub", "%{count} subs", count, count: count) + end + defp format_duration(nil), do: "Unknown" defp format_duration(seconds) when is_integer(seconds) do diff --git a/lib/towerops_web/live/dashboard_live.html.heex b/lib/towerops_web/live/dashboard_live.html.heex index 3593142a..fac1596a 100644 --- a/lib/towerops_web/live/dashboard_live.html.heex +++ b/lib/towerops_web/live/dashboard_live.html.heex @@ -489,7 +489,7 @@ <%= if alert.gaiia_impact && alert.gaiia_impact["total_subscribers"] && alert.gaiia_impact["total_subscribers"] > 0 do %> - {alert.gaiia_impact["total_subscribers"]}s + {format_subscriber_count(alert.gaiia_impact["total_subscribers"])} <% end %> diff --git a/lib/towerops_web/live/device_live/index.ex b/lib/towerops_web/live/device_live/index.ex index 74ee3acb..0b10a27c 100644 --- a/lib/towerops_web/live/device_live/index.ex +++ b/lib/towerops_web/live/device_live/index.ex @@ -547,7 +547,7 @@ defmodule ToweropsWeb.DeviceLive.Index do defp format_subscriber_count(nil), do: nil defp format_subscriber_count(%{subscriber_count: count}) when count > 0 do - "#{count} subs" + ngettext("%{count} sub", "%{count} subs", count, count: count) end defp format_subscriber_count(_), do: nil