Make polls translatable

This commit is contained in:
Julian Herrero
2018-09-20 17:07:43 +02:00
parent c1d705ff30
commit 9495208518
11 changed files with 198 additions and 10 deletions

View File

@@ -28,6 +28,20 @@ section "Creating polls" do
ends_at: 1.month.ago,
results_enabled: true,
stats_enabled: true)
Poll.find_each do |poll|
name = poll.name
I18n.available_locales.map do |locale|
neutral_locale = locale.to_s.downcase.underscore.to_sym
Globalize.with_locale(neutral_locale) do
poll.name = "#{name} (#{locale})"
poll.summary = "Summary for locale #{locale}"
poll.description = "Description for locale #{locale}"
end
end
poll.save!
end
end
section "Creating Poll Questions & Answers" do

View File

@@ -0,0 +1,15 @@
class AddPollTranslations < ActiveRecord::Migration
def self.up
Poll.create_translation_table!(
name: :string,
summary: :text,
description: :text
)
end
def self.down
Poll.drop_translation_table!
end
end

View File

@@ -900,6 +900,19 @@ ActiveRecord::Schema.define(version: 20180813141443) do
add_index "poll_shifts", ["booth_id"], name: "index_poll_shifts_on_booth_id", using: :btree
add_index "poll_shifts", ["officer_id"], name: "index_poll_shifts_on_officer_id", using: :btree
create_table "poll_translations", force: :cascade do |t|
t.integer "poll_id", null: false
t.string "locale", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
t.text "summary"
t.text "description"
end
add_index "poll_translations", ["locale"], name: "index_poll_translations_on_locale", using: :btree
add_index "poll_translations", ["poll_id"], name: "index_poll_translations_on_poll_id", using: :btree
create_table "poll_voters", force: :cascade do |t|
t.string "document_number"
t.string "document_type"