Comments (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)
- check-up-to-date fails even though files are just extracted HOT 8
- Flaky test in `gettext.extract`
- Duplicate Filename in Reference when `:write_reference_line_numbers` is set to `false`
- Gettext.PluralFormError for plural form "1" in "ja" locale HOT 9
- `gettext.merge` FunctionClauseError HOT 4
- Module is not loaded because :nofile HOT 4
- Mention file path in plural forms deprecation warning HOT 4
- Plural Forms warning occurs in newly generated language file HOT 2
- bump a new version for #359 HOT 1
- Duplicate msgid with singular and plural form HOT 5
- Running `mix gettext.extract` doesn't extract new messages with Elixir 1.15 HOT 2
- Retain custom flags during merge HOT 3
- Interpolation option set but not working HOT 4
- Duplicate references in POT files and warnings about redefining modules HOT 5
- compile depend excoveralls - origin/httpc failed HOT 1
- Add `Gettext.example` macro HOT 6
- If changes to `.po` file are discarded (accidentally), they're not added back HOT 17
- Allow to transform messages at compile time HOT 3
- `expo.msguniq` merges translations with different plurals HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gettext.