Matthias,
Unfortunately, this isn't going to work the way you have modeled it :-
( sorry for not telling you right from the start ;-)
Depending on your other requirements, the simple approach provided
earlier in this thread works fine: different status per page per
language.
Good luck,
Juergen
On Jun 6, 2008, at 10:21 AM, Mattias Bodlund wrote:
> Hi - really appreciate your help but I still think we are talking
> about to different scenarios.
>
> I'll try making it more clear:
>
> class Page < ActiveRecord::Base
> self.keep_translations_in_model = true
> translates :status_id
> belongs_to :status
> end
>
> class Status < ActiveRecord::Base
> has_many :pages
> end
>
>
> I also have status_id_en in my page model. Status is not string
> but a association. This means that I would like to be able to
> handle different values on status_id, status_id_en on the same
> record. Which would give me different status.
>
> hope this was more clear.
>
> mattias
>
>
>
> On 06/06/2008, at 15.02, Jürgen Feßlmeier wrote:
>
>> I see, different status per language. In this case, one way you
>> can do this is
>>
>> class Page < ActiveRecord::Base
>> self.keep_translations_in_model = true
>> translates :status
>> ....
>> end
>>
>> Make sure that you put the same label in your status field no
>> matter which locale/lanaguage, say
>>
>> Locale.switch_locale('en') do
>> page.status = 'active' # or 'inactive' in your base language,
>> here English
>> end
>>
>> Locale.switch_locale('de') do
>> page.status = 'active' # or 'inactive'
>> end
>>
>> and finally when you need to display the status use the .t directive
>>
>> page.status.t
>>
>> Hope this helps?
>>
>> Greetings,
>> Juergen
>>
>> On Jun 6, 2008, at 9:51 AM, Mattias Bodlund wrote:
>>
>>> Yes - so far so good - but the page still have the same status.
>>>
>>> Lets say we have two Statuses: active and inactive. Then we have
>>> a Page that should be active in english but inactive in german.
>>>
>>> mattias
>>>
>>> On 06/06/2008, at 14.44, Jürgen Feßlmeier wrote:
>>>
>>>>
>>>> Hi Matthias,
>>>>
>>>> Sure, but i would approach it differently. Say your Status model
>>>> looks like this:
>>>>
>>>> class Status < ActiveRecord::Base
>>>> translates :name
>>>> end
>>>>
>>>>> class Page < ActiveRecord::Base
>>>>> # translates :status_id
>>>>> belongs_to :status
>>>>
>>>> # add method to display the page status
>>>> def status_display
>>>> self.status ? self.status.name : '-'
>>>> end
>>>>
>>>>
>>>>> end
>>>>>
>>>>
>>>>
>>>> Mind you this is quite slow as every time you call
>>>> status_display a query is sent of the DB, worse case if you are
>>>> not using Globalize in table translations. In my view what may
>>>> be better is to have a status field string field in pages model
>>>> and have it translated using .t, like:
>>>>
>>>> page.status.to_s.t
>>>>
>>>> Anyway, hope this helps?
>>>>
>>>> Greetings,
>>>> Juergen
>>>>
>>>>
>>>> On Jun 6, 2008, at 9:27 AM, Mattias Bodlund wrote:
>>>>
>>>>> Can you also translate foreign keys/relations with Globalize.
>>>>> Lets say we have a Page with different statuses in different
>>>>> languages.
>>>>>
>>>>> Lets say we have Page that belongs_to Status.
>>>>>
>>>>> class Page < ActiveRecord::Base
>>>>> translates :status_id
>>>>> belongs_to :status
>>>>> end
>>>>>
>>>>> I get an error trying this:
>>>>> undefined method `direction=' for 2:Fixnum
>>>>>
>>>>> mattias
>>>>>
>>>>>
>>>>
>>>>
>>>
>>
>>
>