shahryarjb

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

idi527

:default_locale is set in :gettext app config, I think.

kip

kip

ex_cldr Core Team

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

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… :wink:

Where Next?

Popular in Questions Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement