0

I'm using the I18n Gem from Sven Fuchs in my Ruby on Rails 3.2 Application and while the gem works great I came across a situation, which I don't know the solution to:

I have a seed file, which contains the basic translation for my MVC's and is seeded, when I install my application on a new machine. The problem is that when one of these translations changes, I have to go to my seed file, edit it, delete in the database and reseed it. Which is problem not the best way to do this.

Furthermore, my application can create complete MVC's on the fly, which of course need translations as well. These translations get only stored in the database. But it would be nice to store them in a real file, keep them under version control and import or export them if I need to.

So, basically what I'm looking for, is an intelligent connection between the translations in my database and the ones in my files. So I can populate one from the other or vica verca and keep them in sync.

And also I looked at solutions like Globalize3 or localeapp, but they don't seem to fit.

Summarized, what I have is:

  • The I18n Gem from Sven Fuchs with a Backend I created myself
  • A Seed File which changes sometimes and has to be edited manually but seeds the basic translations
  • A database which contains translations that are created on the fly and are not under version control, nor stored in some file

What I want:

  • A sync between translations in my seed file and my database
  • A way to put my translations under version control

I'm sure I can't be the only one who needs this...

Thanks in regards!

Thomas
  • 790
  • 6
  • 17
  • I'm curious why you need translations in seed files AND in your database - surely having one or the other would be easier to maintain? – tigrish May 13 '13 at 15:24
  • One of the main features of my application is that it can create other MVCs within the app. So, in the basic version, all my translations come from the seed file. But for every new MVC I create new translations, which are then only stored in the database. And in both cases the user can edit the translations, which means they should be versioned. – Thomas May 13 '13 at 21:44
  • Do you actually need to update the seed file or could you just take backups of your database translations? Two-way syncing is a nightmare! – tigrish May 14 '13 at 10:01

1 Answers1

0

Here is how I solved a problem closer to the question asked:

task :task_name => [:environment] do  

  file = "db/file_name.txt"

  counter = 0

  CSV.foreach(file, :headers => true, :col_sep => "^", :quote_char => "~") do |row|
    identifier = row[0].to_i
    model_name = ModelName.find_or_create_by_identifier(identifier)
    I18n.locale = row[1]
    model_name.name = row[3]
    model_name.save!
  end
end

Note that identifier needs to be a unique identifier that doesn't change and exists in the file and in the database. In this example, the columns are separated by "^" and quores are "~"

As @tigrish said in the comments, it is not a good idea to insert in the file and in the database, so it is important to restrict this.

These links may also help:

As the question is a little old, I hope it can help somebody else.