shahryarjb
How to change default_locale in Gettext
Hello,
I am supposed to create multi language website, therefore I am using gettext for this.
At first I created 3 language in my project and I made translations in it, but I couldn’t change default_locale like its document.
my project gited in GitHub - shahryarjb/ESOGTIPH: Easy sample of gettext in Phoenix 1.3 · GitHub
for example I have 3 lang ["ru", "en", "fa"]
my router :
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
plug SetLocale, gettext: MultiLangWeb.Gettext, default_locale: "fa", cookie_key: "project_locale" #cookie_key is optional
end
pipeline :api do
plug :accepts, ["json"]
end
scope "/", MultiLangWeb do
pipe_through :browser # Use the default browser stack
get "/", PageController, :dummy
end
and my project config :
config :multi_lang, MultiLangWeb.Gettext,
default_locale: "fa"
As you can see, I changed fa insted of en in my config , but it allways loads en default .
How can I changed default_locale to fa or ru?
I had read (Translating Phoenix Applications with GNU gettext | Phrase),but there was no use for me .
please help me for changing it.
Thanks
Most Liked
idi527
:default_locale is set in :gettext app config, I think.
kip
If you try the following, what do you see?
iex -S mix
iex> Gettext.known_locales MultiLangWeb.Gettext
iex> Gettext.default_locale MultiLangWeb.Gettext
The last function call should return fa in your configured case (you shouldn’t need to configure the :locales key).
If for some reason you aren’t seeing fa then I think there is a different problem.
Joep
Just wanted to mention Using Gettext to internationalize a Phoenix application « Plataformatec Blog that gives a very helpful explanation about using Gettext.
It’s the third hit and first article googling “phoenix gettext” but still… ![]()
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








