Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I18n translation with i18n-active_record: same form for same key

I am working on an app in Rails 4 using i18n-active_record 0.1.0 to keep my translations in the database rather than in a .yml-file. It works fine.

One thing that I am struggling with, however, is that each translation record is one record per locale, i.e.

#1. { locale: "en", key: "hello", value: "hello")
#2. { locale: "se", key: "hello", value: "hej")

which makes updating them a tedious effort. I would like instead to have it as one, i.e.:

{ key: "hello", value_en: "hello", value_se: "hej" }

or similar in order to update all instances of one key in one form. I can't seem to find anything about that, which puzzles me.

Is there any way to easily do this? Any type of hacks would be ok as well.

like image 293
Christoffer Avatar asked Aug 05 '16 11:08

Christoffer


1 Answers

You could make an ActiveRecord object for the translation table, and then create read and write functions on that model.

Read function would pull all associated records then combine them into a single hash.

Write function would take your single hash input and split them into multiple records for writing/updating.

like image 162
Joshua Avatar answered Nov 15 '22 09:11

Joshua