tugayac
Hey folks
,
I’m one of the maintainers of the Lotus Web library and we had a request to add i18n support for the library. The requester was nice enough to help with a PR here, but I’m having issues getting it to work locally.
If anyone has experience adding Gettext support to libraries, I could use some help understanding the following (posting here because I don’t believe this is a Phoenix-related issue):
- Why would Gettext not pick up the correct translations, even though the locale seems to be set correctly in the LiveView process? (see PR comment for details)
- Are we adding Gettext support to Lotus Web in the right way, with the goal of allowing users of the library to provide their own translations?
- Is there a recommended way of adding Gettext to Elixir libraries? (I couldn’t find any suggestions in the Gettext docs).
Here’s a diff of what I’m trying (also included in the PR discussion) in another Elixir app that uses this branch:
diff --git a/config/config.exs b/config/config.exs
index 5062c76e..32e717e0 100644
--- a/config/config.exs
+++ b/config/config.exs
+config :lotus_web, Lotus.Web.Gettext,
+ priv: "priv/lotus_gettext",
+ locales: ~w(en tr),
+ default_locale: "tr"
+
import_config "#{config_env()}.exs"
diff --git a/lib/accomplish_web/router.ex b/lib/accomplish_web/router.ex
index 951b8e80..defb9e4c 100644
--- a/lib/accomplish_web/router.ex
+++ b/lib/accomplish_web/router.ex
@@ -48,7 +48,7 @@ defmodule AccomplishWeb.Router do
scope "/admin", AccomplishWeb.Admin do
pipe_through :admin
- lotus_dashboard("/lotus")
+ lotus_dashboard("/lotus", on_mount: [{AccomplishWeb.LocaleHook, :default}])
end
diff --git a/mix.exs b/mix.exs
index ffd13aab..e1e36812 100644
--- a/mix.exs
+++ b/mix.exs
@@ -87,7 +87,7 @@ defmodule Accomplish.MixProject do
- {:lotus_web, "~> 0.6.2"},
+ {:lotus_web, path: "../lotus_web_branch"},
Here’s the Gettext directory structure in my app:
For reference,
default_domain in the PR (for the Lotus Web library) is set to lotus, hence lotus.po.
Trending in Questions
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
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
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
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
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
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
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
derek-zhou
Each of the libraries from the dependency is a OTP application with it’s own
privdir, andpriv/gettextdir. So, I am not sure if you can achieve e your goal of “allowing users of the library to provide their own translations”. Translations are supposed to be faithful; so can you just accept the translation upstream?tugayac
Good point, hadn’t considered that
, we do set
otp_appto Lotus Web when using Gettext.It sounds like the best course of action is just to include it as part of the library as you suggested
I get the feeling we’re trying to use Gettext in a way it wasn’t intended right now.
We could use the dynamic translation features of Gettext, but I do want to keep the compile-time guarantees to avoid breaking translations.
Thanks @derek-zhou
LostKobrakai
This is not as simple. Any of your users has lotus_web as a dependency. Their app won’t start compiling before lotus_web has been fully compiled. You could force a dependency cycle and start compiling parts of their app (gettext backend) before the rest of their app, which might be fine, but also depending on their setup could just as much not be fine at all. If you really want you could add a config to your application, which allows to switch out the folder, where .po files are located. That would allow users to change the translations without messing with the compile time ordering of elixir files.
Given the context I’d probably agree with the suggestion to keep the translations as part of the package though. I can see users wanting to have the UI localized, but less so the ask for customizing the localizations beyond what would be useful to all users.
tugayac
@LostKobrakai I was referring to using the Gettext functions instead of macros when I said “dynamic translation features of Gettext” (i.e. this section of the Gettext docs), in which case the compile order shouldn’t matter (because translations should be fetched at runtime, but maybe I misunderstand how Gettext works?).
With Gettext macros, yes what you said makes sense
Yep, we decided to go that direction