Thursday, 15 August 2013

ruby on rails 4 - Globalize: How to show in the view the current locale information -



ruby on rails 4 - Globalize: How to show in the view the current locale information -

i having bit of problem globalize gem.

i explain current situation: have model called question. after creating it, without info stored, added next lines model:

class question < activerecord::base translates :wording, :answer1, :answer2, :answer3, :answer4 end

then, created migration create translations table

class createtranslationstable < activerecord::migration def question.create_translation_table! :wording => :string, :answer1 => :string, :answer2 => :string, :answer3 => :string, :answer4 => :string def end def downwards question.drop_translation_table! def end

my default locale :en. after added data.

if go execute rails c , set command question.first.wording works fine. although when execute in 'rails c' i18n.locale = :es , question.first.wording still displays english language text set @ beginning.

i tried 1 thing seemed help me dropped translated columns (like specified in globalize documentation after migrated data. in case didn't have info migrate @ origin though). after made rollback (which got columns deleted form question model), executing question.first.wording i18n.locale = :es got working. means question.first.wording returns nil.

after that, implemented 'locale url params' specified in ruby on rails guide means first url param si ':locale' param. current problem: view still displays info in english language when should display in spanish, since url entered http://localhost.com/es/questions/.

how can create display in view spanish information?

my mistake. interpreted documentation the chunck of code (in application_controller.rb) works setting url:

def default_url_options(options={}) { locale: params[:locale] } end

would set 'i18n.locale' variable. did next around (in application_controller.rb):

before_action :change_to_current_locale def change_to_current_locale i18n.locale = params[:locale] end

that made work.

ruby-on-rails-4 globalize

No comments:

Post a Comment