Hey, I want to localize some of my model's attributes. I've found that there are lots of gems (globalize, puret) which use the same approach, just like following:
(pseudocode)
begin
class Institution
attr: name_to_be_localized
set locale开发者_高级运维 to X
Institution.name = "blabla"
set locale to Y
Institution.name = "plapla"
end
Is there another way to write / access data in a localized form, maybe indicating the desired language and append it to the attribute?
I18n will let you do this, by manipulating the I18n.locale attribute (ie get/set methods):
>> helper.t('hello_world')
=> "Hello you"
>> I18n.locale = :de
=> :de
>> helper.t('hello_world')
=> "Guten Tag"
>> I18n.locale = :en
=> :en
>> helper.t('hello_world')
=> "Hello you"
I don't know if this will do quite what you want though. Do you mean that if someone is editing an object/record while locale is :de and another edits the same object/record while the locale is :en then the two values don't overwrite each other but instead get saved in different fields?
精彩评论