Better way to handle gettext updates when using push_patch

Looking at: Gettext_sigils - a sigil for using gettext with less boilerplate and better readability

(which is a really nice piece of work) made me come back and examine the way I am handling language switches right now.

Aiming for a good user experience, I switched from push_navigate to push_patch.

While this is good enough and works well with push_navigate:

def render(assigns) do
  ~H"""
    <div>
       {gettext("Works without an explicit @locale")}
    </div>
  """
 end

Using push_patch I had to reference @locale explicitly to get a proper DOM render
(well knowing that this is not a supported keyword but this way it looks more obvious to me):

def render(assigns) do
  ~H"""
    <div>
       {gettext("Needs an explicit @locale", locale: @locale)}
    </div>
  """
 end

Is there a way to handle this better nowadays?

And of course I’d prefer to be able to use the new gettext sigil ~t together with push_patch

I’d suggest sticking to push_navigate. Gettext being process dict based doesn’t compose well with LVs change tracking, which needs explicit parameter passing. You can work around the limitation by foregoing the the process dict and explicitly providing the locale to gettext, but that’s verbose:

<p>{Gettext.with_locale(@locale, fn -> gettext("Hello world") end)}</p>

Thx for chiming in.

Sadly push_patch is so much faster (feels more instant) especially on a slower connection.
But then: a language-change is an event which does not happen very often.

Gettext.with_locale indeed is verbose.