shahryarjb
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
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Hello,
I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
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
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
idi527
:default_localeis set in:gettextapp config, I think.shahryarjb
Unfortunately, It does not work for me
I have tested this before
or just
my project gited in GitHub - shahryarjb/ESOGTIPH: Easy sample of gettext in Phoenix 1.3 · GitHub
idi527
Maybe you need to change the process’s locale and not the default locale for the app? Then you need to set it in one of your plugs probably.
It will store locale info in the process dictionary and all subsequent operations in that process would have access to it.
shahryarjb
Hello ,
may you test my project in github because I can’t fix it? I think Gettext loads everything on config file and doesn’t show any reaction to put_locale/1 .
I have entered
Gettext.get_locale(MultiLangWeb.Gettext)in terminal andGettext.put_locale(MultiLangWeb.Gettext, "fa"), after that I have tested Gettext.get_locale(MultiLangWeb.Gettext)and it shows mefa, but I have a problem yet.The
enis still default page.May I not know where I can enter the put_locale?
idi527
Maybe in a plug somewhere before the controller action.
You seem to be doing it with ESOGTIPH/lib/multi_lang_web/router.ex at master · shahryarjb/ESOGTIPH · GitHub already. Now you need to provide the appropriate
accept-languageheaders in your request for it to work.idi527
Or not, I’m a bit confused at what GitHub - smeevil/set_locale: elixir phoenix plug that can extract locale from browser headers or paths for redirection and setting of get text locales · GitHub actually does.
Maybe try https://github.com/kipcole9/cldr with its plugs.
I personally find it easier to write these little plugs myself …
thib
Hi
Had the same problem here ; I found few things on Google and ended up with that. Default language will be used until the user sends a locale in params, then it will be stored in a simple cookie. Just use it in your plug and you should be fine.
I tried to make it work with get_req_header(conn, “accept-language”), but never found how to do nor why I should use that…
Kurisu
I followed this tutorial and it works for me: Phoenix I18n.
The difference I noticed at first glance between the way you’re setting default locale in config is that you don’t provide the full list of supported locales.
For example
config :demo, I18ndemoWeb.Gettext, default_locale: ru, locales: ~w(en ru)I hope it will heelp…
That works for me.
kip
If you try the following, what do you see?
The last function call should return
fain your configured case (you shouldn’t need to configure the:localeskey).If for some reason you aren’t seeing
fathen 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…