Git Product home page Git Product logo

Comments (1)

maennchen avatar maennchen commented on June 7, 2024 1

@itrelease The initial render of liveview and the socket rendered version don't work completely the same.

The initial render runs normally through your router and all plugs. But the socket version runs through the socket declared in your endpoint. That one does not run all your plugs.

Gettext persists the chosen language in the process dictionary. That does not work for a live view since the initial render and the web socket render are in different processes.

There's multiple ways to make sure that live view does the language correctly. I've personally used ex_cldr and its Cldr.Plug.PutSession plug. The session you can also read in your live view and set the locale accordingly.

You can see this used in an older project of mine (not the most current live view version): https://github.com/jshmrtn/hygeia/blob/main/lib/hygeia_web/live/init/locale.ex

Another way would be to pass the contents of navigator.languages to your LiveSocket params in JS and read that result.

To not repeat that same setup in every live view, on_mount can be used to only write the setup code once.

Phoenix also dedicated a whole guide on the topic: https://hexdocs.pm/phoenix_live_view/using-gettext.html#content

I'll close this issue since this is not a Gettext problem but more of an issue how phoenix / live view are being used.

from gettext.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.