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

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews