Thanks Chris and Warren, it helps me a lot.

Regards
Jeff

On Wed, Oct 13, 2010 at 7:54 AM, Warren Seen <[email protected]> wrote:

> Hey Jeff,
>
> There's no need to use a hash, just use symbols, e.g. in your user model
> define it as something like:
>
> GenderOptions = [:male, :female]
>
> (So you can use User::GenderOptions for validation and option list
> creation)
>
> Then in your config/locales/en.yml, you put your translated names for the
> genders.
>
> en:
>  gender:
>    male: "Man"
>    female: "Woman"
>
> Then, you can use the scope parameter of I18n#t, like this:
> >> user.gender = :male
> >> I18n.t(user.gender, :scope => :gender) # or just use the helper,
> t(user.gender, :scope => :gender) in your views
> => "Man"
>
> I18n#t will also accept a string, so you don't have to worry about
> converting between strings and symbols either, :male and 'male' can be used
> interchangeably.
>
> I hope that helps. There's a full guide for i18n at
> http://guides.rubyonrails.org/i18n.html that is well worth referring to.
>
> Also, on your other question, I'd say that you're probably going to be
> better off to start on Rails 3, even if your gem/plugin choice is restricted
> somewhat, you should find more than enough that is compatible to get started
> in Rails.
>
> Warren
>
> On 13/10/2010, at 12:38 AM, Jeff Yu wrote:
>
> > Second question is related to the 'dictionary' type data. for example,
> > I have "Gender" field in my model, normally, I will use Hash for this,
> > like [ :1 => "Female", :2 => "Male"], meanwhile, I want to get those
> > 'Female' and 'Male' to be able i18n. I am not sure how we do this in
> > the Rails way. Should I create a separate model for these data, or put
> > these data along with their own models?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby or Rails Oceania" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<rails-oceania%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rails-oceania?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" 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-oceania?hl=en.

Reply via email to