Translation arrays not parsed correctly #123

Closed
activestylus opened this Issue Nov 19, 2009 · 7 comments

Projects

None yet

2 participants

@activestylus

When using a collection we get these weird id numbers as values instead of strings

Translation file

en:
titles:
- Mr
- Ms
- Dr

f.input :title, :as=>:select, :collection=> I18n.t('titles')

This will give me options that look like this

Mr
Ms
Dr

Clearly not what I was looking for - maybe to_s needs to be called somewhere?

@activestylus

Damn that comment just ate my code - all you need to know is that the option values are usually integers instead of the desired string

@grimen

Sorry, I don't understand your question. Could you clearify what you expect? Also, I would suggest putting the code in a gist or pastie.

@grimen

Sorry, I can't reproduce this. Can't get the spec to fail even with loading a raw YAML file. Either we need a failing spec or a physical proof (see http://github.com/grimen/test_app) - or it'll be closed.

Data:

en:
  titles:
    - Mr
    - Ms
    - Dr

Spec (one of them, all different flavors passed)

describe "from I18n lookup" do
      before do
        translations = File.open(File.join(File.dirname(__FILE__), *%w[.. data en.yml])) { |file| YAML.load(file) }
        ::I18n.backend.store_translations :en, ::HashWithIndifferentAccess.new(translations)[:en]
        
        semantic_form_for(@new_post) do |builder|
          concat(builder.input(:title, :as => :select, :collection => ::I18n.t(:titles)))
        end
      end
      
      it "should load option values correctly" do
        output_buffer.should have_tag('form li select option', 'Mr')
        output_buffer.should have_tag('form li select option', 'Ms')
        output_buffer.should have_tag('form li select option', 'Dr')
      end
    end
@activestylus

I spoke with our team about this and it turns out the problem is related to our use of Globalize. I tested out a fresh app and did not have this issue but as soon as I installed Globalize I got those weird integers.

As a temporary fix I just do something like this:

:collection => I18n.translate('titles').map(&:to_s)

Which gives the desired result.

@grimen

OK, great. I had major issues with Globalize and GLobalize 2, so I dropped it for good. Doin fine without it - there are thinner alternatives that work very well for me: http://github.com/janne/model_translations

Closing this.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment