Hey. I’m currently developing my first application using gettext and I noticed that with the default generator, the Gettext module gets created in the
MyAppWeb context. Now I’m wondering why it’s put there and not in the main
I have a few places where I would need the
Gettext module within my main context. Use cases where I would need translations inside of the
- default values for Ecto schemas
- E-Mail text
Any suggestions how I should handle that? Or should I simply move the Gettext module inside
I would move it to MyApp in that case. Being in MyAppWeb is only a suggestion in the basic project layout, you don’t need to adhere to it. Maybe some config settings need to be changed to point to the new module name though.
Thanks. That’s probably what I’m going to do. I just wanted to make sure that I’m not missing something obvious - like that it’s absolutely discouraged to do so
Locale is per process; and is usually set up through a plug so the controller context has the right locale. In your own process like in a GenServer, you need to do the setup yourself, and you will need to consider the cases when different clients are using different locales at the same time, so it may become less clear what is the right locale.