Yoga

Yoga

Maybe I am doing something wrong but I can’t find anything about i18n in Phoenix docs.

Also, I have noticed, that for some reason the lang tag is hardcoded in the default root template as “en”.

Also, I can’t find anything about locales, default_locale, fallback_locale as in other frameworks like Laravel.

I do see gettext folder.

Why is there gettext folder and locales are completely missing?

Also, is there a tutorial on how to setup a Phoenix app with a typical urls like / and /de/ and /ua/ ?

I have checked LiveView help and there, also, is nothing about making the website multilingual.

Showing Posts 1 to 10

LostKobrakai

LostKobrakai

Phoenix uses the gettext library to do i18n. You can find its documentation here: Gettext — gettext v1.0.2

al2o3cr

al2o3cr

Like @LostKobrakai said, most of the docs you’ll need are under the Gettext library.

I found this tutorial that looks useful; it demonstrates doing the URL-locale thing:

kokolegorille

kokolegorille

In addition, it’s also possible to setup locale in live socket with this kind of code in assets/js/app.js

let liveSocket = new LiveSocket("/live", Socket, {
  params: {
    _csrf_token: csrfToken,
    locale: Intl.NumberFormat().resolvedOptions().locale,
    timezone_offset: -(new Date().getTimezoneOffset() / 60),
  }
});

So that liveview is aware of client locale

zaljir

zaljir

And for Liveview, more docs can be found here: Using Gettext for internationalization — Phoenix LiveView v0.18.3

Yoga

Yoga OP

I keep seeing the jargon “backend module” all the time. What does that mean? What is backend in this module context? Admin area? Protected area?

Yoga

Yoga OP

Hmm, thanks, will take a look. Hopefully, it will work with LiveView.

Yoga

Yoga OP

How do you make

<html lang="en">

dynamic and not hardcoded in root template using LiveView?

In Laravel it is done like this:

<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

How do you achieve this in Phoenix?

And again, why isn’t it already there in the first place? Together with the locales and default locale? For example, in Laravel it is set in config/app.php file, namely locale, default_locale, fallback_locale and faker_locale. I mean at least the locale could be put in config/config.exs somewhere by default ;(

As it is now, it seems half baked meaning you got gettext but you are missing locales and local is hardcoded in the root template file.

Yoga

Yoga OP

I followed it and the URL part doesn’t work with LiveView. I see the English version all the time. I thought it is working when I tried /nl first time and it showed the NL content, however then I manually tried /en and English showed. Then I tried again /nl but English was shown there:

Shouldn’t this part in root.html.heex:

<!DOCTYPE html>
<html lang="en">

be something like

<!DOCTYPE html>
<html lang="<%= my_current_locale() %>">

or something?

Another problem if I have this in routes:

  scope "/:locale", MyWeb do
    pipe_through :browser

    live "/", HomeLive
  end

/ doesn’t work anymore, although it should work as the default language . /nl and /en work but only English is shown.

so:

http://localhost:4000/   <-- this should show the default language but doesn't
http://localhost:4000/en   <-- this works 
http://localhost:4000/nl   <-- this works but showed the NL content correctly only first time, after refresh English
Yoga

Yoga OP

That’s only for logging it seems. For guests it has no impact and LiveView doesn’t show gettext correctly at least for me.

Yoga

Yoga OP

I have found this library now Phoenix Localized Routes - Localized/multilingual routes in Phoenix but the things you have to change in the example_web.ex file are missing in Phoenix 1.7 . Also, the project seems to be temporarily or permanently down, at least for me: https://bartotten.github.io/phoenix_localized_routes/

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
csmr
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley: Mutonex gamedesign was finish...
New
perzanko
Do we have maintainer of absinthe-graphql/dataloader here? We have a PR that we’d like to merge to the library. Relatively small additive...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews