5

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

 3 years ago
source link: https://www.codesd.com/item/i18n-translation-with-i18n-active-record-same-form-for-same-key.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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

advertisements

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.


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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK