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
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
Postgres can certainly select only parts of json fields. I’m not sure if Trans uses it though.
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 
https://www.compose.com/articles/faster-operations-with-the-jsonb-data-type-in-postgresql/ 
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.







