diff --git a/Gemfile b/Gemfile index 5430c9c41..bf657d345 100644 --- a/Gemfile +++ b/Gemfile @@ -53,6 +53,7 @@ gem 'pg_search' gem 'ahoy_matey', '~> 1.2.1' gem 'groupdate' # group temporary data +gem 'tolk' # Web interface for translations gem 'browser' gem 'turnout' diff --git a/Gemfile.lock b/Gemfile.lock index 4756e3aed..fafb13808 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -344,6 +344,7 @@ GEM rspec-support (~> 3.4.0) rspec-support (3.4.1) ruby-progressbar (1.7.5) + safe_yaml (1.0.4) sass (3.4.21) sass-rails (5.0.4) railties (>= 4.0.0, < 5.0) @@ -397,6 +398,9 @@ GEM thread_safe (0.3.5) tilt (2.0.2) tins (1.6.0) + tolk (1.9.3) + rails (>= 4.0, < 4.3) + safe_yaml (>= 0.8.6) turbolinks (2.5.3) coffee-rails turnout (2.2.1) @@ -496,6 +500,7 @@ DEPENDENCIES social-share-button! spring spring-commands-rspec + tolk turbolinks turnout uglifier (>= 1.3.0) diff --git a/config/initializers/tolk.rb b/config/initializers/tolk.rb new file mode 100644 index 000000000..2284aa921 --- /dev/null +++ b/config/initializers/tolk.rb @@ -0,0 +1,25 @@ +# encoding: utf-8 + +# Tolk config file. Generated on January 14, 2016 12:09 +# See github.com/tolk/tolk for more informations + +Tolk.config do |config| + + # If you need to add a mapping do it like this : + # May we suggest you use http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes + # config.mapping['en-AU'] = 'English (Australia)' + # config.mapping['es-MX'] = 'Spanish (Mexico)' + # config.mapping['fr-ES'] = 'FraƱol !' + # config.mapping['is'] = 'Icelandic' + # config.mapping['vi'] = 'Vietnamese' + + # Master source of strings to be translated + config.primary_locale_name = 'en' +end + +Tolk::ApplicationController.authenticator = proc { + authenticate_or_request_with_http_basic do |username, password| + username == Rails.application.secrets.translate_username && + password == Rails.application.secrets.translate_password + end +} diff --git a/config/routes.rb b/config/routes.rb index d10ffefd7..d0fa9f576 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -280,6 +280,8 @@ Rails.application.routes.draw do mount LetterOpenerWeb::Engine, at: "/letter_opener" end + mount Tolk::Engine => '/translate', :as => 'tolk' + # static pages get '/blog' => redirect("http://diario.madrid.es/participa/") diff --git a/config/secrets.yml.example b/config/secrets.yml.example index 450f0b09f..6e67e57c8 100644 --- a/config/secrets.yml.example +++ b/config/secrets.yml.example @@ -33,9 +33,12 @@ production: &production google_oauth2_key: "" google_oauth2_secret: "" + translate_username: "" + translate_password: "" + rollbar_server_token: "" server_name: "" preproduction: server_name: "" - <<: *production \ No newline at end of file + <<: *production diff --git a/db/migrate/20160114110933_create_tolk_tables.rb b/db/migrate/20160114110933_create_tolk_tables.rb new file mode 100644 index 000000000..160000ab0 --- /dev/null +++ b/db/migrate/20160114110933_create_tolk_tables.rb @@ -0,0 +1,38 @@ +class CreateTolkTables < ActiveRecord::Migration + def self.up + create_table :tolk_locales do |t| + t.string :name + t.datetime :created_at + t.datetime :updated_at + end + + add_index :tolk_locales, :name, :unique => true + + create_table :tolk_phrases do |t| + t.text :key + t.datetime :created_at + t.datetime :updated_at + end + + create_table :tolk_translations do |t| + t.integer :phrase_id + t.integer :locale_id + t.text :text + t.text :previous_text + t.boolean :primary_updated, :default => false + t.datetime :created_at + t.datetime :updated_at + end + + add_index :tolk_translations, [:phrase_id, :locale_id], :unique => true + end + + def self.down + remove_index :tolk_translations, :column => [:phrase_id, :locale_id] + remove_index :tolk_locales, :column => :name + + drop_table :tolk_translations + drop_table :tolk_phrases + drop_table :tolk_locales + end +end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 7bc4652d9..2924fed64 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160108133501) do +ActiveRecord::Schema.define(version: 20160114110933) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -323,6 +323,32 @@ ActiveRecord::Schema.define(version: 20160108133501) do add_index "tags", ["proposals_count"], name: "index_tags_on_proposals_count", using: :btree add_index "tags", ["spending_proposals_count"], name: "index_tags_on_spending_proposals_count", using: :btree + create_table "tolk_locales", force: :cascade do |t| + t.string "name" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "tolk_locales", ["name"], name: "index_tolk_locales_on_name", unique: true, using: :btree + + create_table "tolk_phrases", force: :cascade do |t| + t.text "key" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "tolk_translations", force: :cascade do |t| + t.integer "phrase_id" + t.integer "locale_id" + t.text "text" + t.text "previous_text" + t.boolean "primary_updated", default: false + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "tolk_translations", ["phrase_id", "locale_id"], name: "index_tolk_translations_on_phrase_id_and_locale_id", unique: true, using: :btree + create_table "users", force: :cascade do |t| t.string "email", default: "" t.string "encrypted_password", default: "", null: false