A nice idea you got there.
The thing is I am migrating my models from globalize1 in-table
translations so your generated migration was a great starting point.
This is what I did:
Post.find(:all).each do |obj|
PostTranslation.create(
"title" => obj.attributes["title"],
"text" => obj.attributes["text"],
:locale => "sr",
"post" => obj
)
PostTranslation.create(
"title" => obj.attributes["title_en"],
"text" => obj.attributes["text_en"],
:locale => "en",
"post" => obj
)
end
Maybe this can be automated?
One more thing, when migrating down I was getting uninitialized
constant "PostTranslation" until I've put "Post.find(:first)" before
"PostTranslation.find_by_locale"
Greets,
Mirko
On Jan 15, 11:00 pm, Niels Ganser <[email protected]> wrote:
> Josh,
>
> thanks for the kind words.
>
> You're right that the generator targets applications with existing
> models. I initially created it this way since that was the need I
> currently had.
>
> Upon thinking about other use cases though, I came the conclusion that
> it doesn't make much sense to offer two differentmigrationgenerators
> (one which migrates data over from/to existing models, and one which
> doesn't but just creates atranslationtable).
>
> Instead, I would suggest adding a TranslatableModel generator. This
> would work much like the stock model generator with the addition of a
> translates :column stub to the model itself and a model_translations
> migraton.
>
> I think this should be combined in one generator because either you
> already have a model that you retroactively want to make translatable
> -- in which case you probably want to migrate your existing data over
> as well -- or you don't have a model at all and plan for it to be
> translatable right form the get-go -- in which case you would
> probably ./script/generate model anyways.
>
> Hope this makes sense. I'm very interested in how others see this as
> well!
>
> Best,
> Niels
>
> On Jan 15, 10:05 pm, Joshua Harvey <[email protected]> wrote:
>
> > Thanks, Niels, this looks pretty awesome. I like how it automatically
> > migrates the data!
> > This generator is good for the situation where you already have
> > non-translated models and you want to move over to Globalize2. It probably
> > won't work for new apps where you want to translate fields from the
> > beginning, or for migrating from Globalize1. I'd like to hear from other
> > Globalize users whether they think this will be a common situation for them.
>
> > -- Josh
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"rails-i18n" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rails-i18n?hl=en
-~----------~----~----~----~------~----~------~--~---