Make answers translatable

This commit is contained in:
Julian Herrero
2018-09-20 17:13:40 +02:00
parent 5e6248d2ac
commit 673ec075eb
13 changed files with 258 additions and 28 deletions

View File

@@ -60,9 +60,17 @@ section "Creating Poll Questions & Answers" do
question.save!
Faker::Lorem.words((2..4).to_a.sample).each do |title|
description = "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>"
Poll::Question::Answer.create!(question: question,
title: answer.capitalize,
description: description)
answer = Poll::Question::Answer.new(question: question,
title: title.capitalize,
description: description)
I18n.available_locales.map do |locale|
neutral_locale = locale.to_s.downcase.underscore.to_sym
Globalize.with_locale(neutral_locale) do
answer.title = "#{title} (#{locale})"
answer.description = "#{description} (#{locale})"
end
end
answer.save!
end
end
end
@@ -196,10 +204,19 @@ section "Creating Poll Questions from Proposals" do
proposal = Proposal.all.sample
poll = Poll.current.first
question = Poll::Question.create(poll: poll)
Faker::Lorem.words((2..4).to_a.sample).each do |answer|
Poll::Question::Answer.create!(question: question,
title: answer.capitalize,
description: Faker::ChuckNorris.fact)
Faker::Lorem.words((2..4).to_a.sample).each do |title|
description = "<p>#{Faker::ChuckNorris.fact}</p>"
answer = Poll::Question::Answer.new(question: question,
title: title.capitalize,
description: description)
I18n.available_locales.map do |locale|
neutral_locale = locale.to_s.downcase.underscore.to_sym
Globalize.with_locale(neutral_locale) do
answer.title = "#{title} (#{locale})"
answer.description = "#{description} (#{locale})"
end
end
answer.save!
end
question.copy_attributes_from_proposal(proposal)
title = question.title
@@ -218,10 +235,19 @@ section "Creating Successful Proposals" do
proposal = Proposal.all.sample
poll = Poll.current.first
question = Poll::Question.create(poll: poll)
Faker::Lorem.words((2..4).to_a.sample).each do |answer|
Poll::Question::Answer.create!(question: question,
title: answer.capitalize,
description: Faker::ChuckNorris.fact)
Faker::Lorem.words((2..4).to_a.sample).each do |title|
description = "<p>#{Faker::ChuckNorris.fact}</p>"
answer = Poll::Question::Answer.new(question: question,
title: title.capitalize,
description: description)
I18n.available_locales.map do |locale|
neutral_locale = locale.to_s.downcase.underscore.to_sym
Globalize.with_locale(neutral_locale) do
answer.title = "#{title} (#{locale})"
answer.description = "#{description} (#{locale})"
end
end
answer.save!
end
question.copy_attributes_from_proposal(proposal)
title = question.title

View File

@@ -0,0 +1,14 @@
class AddPollQuestionAnswerTranslations < ActiveRecord::Migration
def self.up
Poll::Question::Answer.create_translation_table!(
title: :string,
description: :text
)
end
def self.down
Poll::Question::Answer.drop_translation_table!
end
end

View File

@@ -829,6 +829,18 @@ ActiveRecord::Schema.define(version: 20180813141443) do
add_index "poll_partial_results", ["origin"], name: "index_poll_partial_results_on_origin", using: :btree
add_index "poll_partial_results", ["question_id"], name: "index_poll_partial_results_on_question_id", using: :btree
create_table "poll_question_answer_translations", force: :cascade do |t|
t.integer "poll_question_answer_id", null: false
t.string "locale", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "title"
t.text "description"
end
add_index "poll_question_answer_translations", ["locale"], name: "index_poll_question_answer_translations_on_locale", using: :btree
add_index "poll_question_answer_translations", ["poll_question_answer_id"], name: "index_85270fa85f62081a3a227186b4c95fe4f7fa94b9", using: :btree
create_table "poll_question_answer_videos", force: :cascade do |t|
t.string "title"
t.string "url"