blisscs

blisscs OP

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.

First 9 of 9 Posts Switch mode

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.

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.

Cochonours

Cochonours

This hstore thing and trans project are interesting, but am I wrong in my understanding that the application will retrieve all the translations from the DB before filtering one for the desired locale? That seems really inefficient to me, and the more you add locales the worse it becomes..?

I’m interested because I’m wondering about this kind of things now too. Wouldn’t the most efficient option be to duplicate columns for every locale? No joins, no fat around the filtered and retrieved data. But then the queries become a pain to write… And the schemas too.

blisscs

blisscs OP

Thank you @hauleth and @OvermindDL1 for your information and recommendation.
trans project looks really interesting.
I think poeditor service could be a solution for this also, but it’s a paid service.
I will be checking on poeditor service and trans.
Will end up picking one of them for this solution.

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.

Cochonours

Cochonours

I understood everything is fetched in one query, and avoiding joins which is nice, but for every translatable field it will fetch a map containing all the possible translations in order to filter for the desired one afterwards. Right? If yes, it’s convenient indeed but what a waste of bandwidth. If no, it means that postgres can filter within the fields he knows contain maps/json : that would be neat and I would like to be sure in order to hop into that wagon.

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 :
PostgreSQL: Documentation: 9.3: JSON Functions and Operators :sunny:
https://www.compose.com/articles/faster-operations-with-the-jsonb-data-type-in-postgresql/ :smile:

OvermindDL1

OvermindDL1

It does, it adds a translated macro that can be used in query’s (anywhere to reference the specific field, so in where’s, select’s, etc…).

— All posts loaded —

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
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
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
Damirados
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement