Connection lost
Reconnecting. If you just saved something, check that it saved before trying again.
Server error
Reconnecting to the server. If you just saved something, check that it saved before trying again.
Pluralization using Gettext in Elixir.
0 comments
I was previously using this to pluralise,
<%= if @items == 1,
do: "#{@items} item",
else: "#{@items} items" %>
# Output
#0 items
#1 item
#2 items
You can cleanly and more efficiently achieve this by using Gettext.ngettext which removes the if else blocks.
<%= ngettext("1 item", "#{count} items", @items) %>
#Trying it on iex
iex> Gettext.ngettext(MyAppWeb.Gettext, "1 item", "%{count} items", 0)
# "0 items"
iex(11)> Gettext.ngettext(MyAppWeb.Gettext, "1 item", "%{count} items", 1)
# "1 item"
iex(12)> Gettext.ngettext(MyAppWeb.Gettext, "1 item", "%{count} items", 10)
# "10 items"