blisscs

blisscs

Gettext Backed by DB (ecto)

Hi,

I have project requirements that I need to provide an interface to user for translating text on the page manually.
I am wondering is it possible to use gettext library and then configure it to use translation from DB instead of .po files so that I can provided an simple web interface to allow user to translate text.

Best
Dev.

Most Liked

OvermindDL1

OvermindDL1

If you want something a bit more specific to full DB language translations instead of just gettext style things (which you can do with a simple DB lookup and maybe a cache) then trans might be what you want as well.

hauleth

hauleth

No, AFAIK it is not possible. What you can achieve though is that you can provide your own helper that will localise the field from the DB, for example you if you store text in PostgreSQL and you use hstore plugin to localise fields then you can do:

def localise_db(field) do
  field[Gettext.get_locale()]
end

And then in your views use localise_db article.title.

LostKobrakai

LostKobrakai

Postgres can certainly select only parts of json fields. I’m not sure if Trans uses it though.

Cochonours

Cochonours

Oh nice, I’m going to look it up now as it makes this perfect for storing translations this way. I’ll test and inspect the SQL generated by Trans when I have time to check that!

Edit :
https://www.postgresql.org/docs/9.3/functions-json.html :sunny:
https://www.compose.com/articles/faster-operations-with-the-jsonb-data-type-in-postgresql/ :smile:

sfusato

sfusato

Trans makes use of a translations field (a map basically => jsonb in Postgres) you’ll store in the database in your model schema that will contain the translations of the fields you need translated. So, it’s not an extra db query as you would fetch it normally with the rest of the model.

And then simply call to Trans with the fetched model that already contains all translations, field to translate and the locale.

Where Next?

Popular in Questions Top

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
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
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
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
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
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

We're in Beta

About us Mission Statement