diff --git a/Gemfile b/Gemfile index 5cb5a80..642bf29 100644 --- a/Gemfile +++ b/Gemfile @@ -3,8 +3,6 @@ source "http://rubygems.org" gem "rails", "3.2.7" gem 'i18n', '0.6.11' gem 'yajl-ruby', require: 'yajl/json_gem' -gem "mongo", "1.1" -gem "bson_ext", ">=1.0.5" gem "redis" if RUBY_VERSION < '1.9' diff --git a/Gemfile.lock b/Gemfile.lock index f4f1519..f9d0485 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -28,10 +28,8 @@ GEM activesupport (3.2.7) i18n (~> 0.6) multi_json (~> 1.0) - arel (3.0.2) - bson (1.2.4) - bson_ext (1.2.4) - builder (3.0.3) + arel (3.0.3) + builder (3.0.4) capybara (1.1.2) mime-types (>= 1.16) nokogiri (>= 1.3.3) @@ -42,34 +40,34 @@ GEM cgi_multipart_eof_fix (2.5.0) childprocess (0.5.3) ffi (~> 1.0, >= 1.0.11) - coderay (1.0.8) + coderay (1.1.0) diff-lcs (1.1.3) erubis (2.7.0) fastthread (1.0.7) ffi (1.9.3) - hike (1.2.1) + hike (1.2.3) i18n (0.6.11) journey (1.0.4) - json (1.7.5) + json (1.8.1) mail (2.4.4) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) - method_source (0.8) - mime-types (1.19) - mongo (1.1) - bson (>= 1.0.5) + method_source (0.8.2) + mime-types (1.25.1) + mini_portile (0.6.0) multi_json (1.10.1) - nokogiri (1.5.5) - polyglot (0.3.3) - pry (0.9.10) - coderay (~> 1.0.5) - method_source (~> 0.8) - slop (~> 3.3.1) - rack (1.4.1) + nokogiri (1.6.3.1) + mini_portile (= 0.6.0) + polyglot (0.3.5) + pry (0.10.1) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + rack (1.4.5) rack-cache (1.2) rack (>= 0.4) - rack-ssl (1.3.2) + rack-ssl (1.3.4) rack rack-test (0.6.2) rack (>= 1.0) @@ -88,57 +86,57 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) - rake (0.9.2.2) - rdoc (3.12) + rake (10.3.2) + rdoc (3.12.2) json (~> 1.4) - redis (2.1.1) - rspec (2.11.0) - rspec-core (~> 2.11.0) - rspec-expectations (~> 2.11.0) - rspec-mocks (~> 2.11.0) - rspec-core (2.11.1) - rspec-expectations (2.11.3) - diff-lcs (~> 1.1.3) - rspec-mocks (2.11.3) - rspec-rails (2.11.0) + redis (3.1.0) + rspec-collection_matchers (1.0.0) + rspec-expectations (>= 2.99.0.beta1) + rspec-core (2.99.2) + rspec-expectations (2.99.2) + diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.99.2) + rspec-rails (2.99.0) actionpack (>= 3.0) + activemodel (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec (~> 2.11.0) + rspec-collection_matchers + rspec-core (~> 2.99.0) + rspec-expectations (~> 2.99.0) + rspec-mocks (~> 2.99.0) rubyzip (1.1.6) selenium-webdriver (2.42.0) childprocess (>= 0.5.0) multi_json (~> 1.0) rubyzip (~> 1.0) websocket (~> 1.0.4) - slop (3.3.3) + slop (3.6.0) sprockets (2.1.3) hike (~> 1.2) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - thor (0.16.0) - tilt (1.3.3) + thor (0.19.1) + tilt (1.4.1) timecop (0.3.5) - treetop (1.4.11) + treetop (1.4.15) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.33) + tzinfo (0.3.41) websocket (1.0.7) xpath (0.1.4) nokogiri (~> 1.3) - yajl-ruby (1.1.0) + yajl-ruby (1.2.1) PLATFORMS ruby DEPENDENCIES - bson_ext (>= 1.0.5) capybara (= 1.1.2) cgi_multipart_eof_fix diff-lcs (= 1.1.3) fastthread i18n (= 0.6.11) - mongo (= 1.1) pry rails (= 3.2.7) redis diff --git a/README.rdoc b/README.rdoc index 230aa19..c030a9c 100644 --- a/README.rdoc +++ b/README.rdoc @@ -2,19 +2,19 @@ == Installation -=== For MongoDB: +=== For Redis: Create Gemfile and run "bundle": - gem 'mongo' - gem 'bson_ext' + gem 'redis' gem 'translator', :git => "git://github.com/amberbit/translator.git" Create initializer, for example config/initializers/translator.rb: - conn = Mongo::Connection.new.db("translator_test").collection("translations") - Translator.current_store = Translator::MongoStore.new(conn) + + Translator.current_store = Translator::RedisStore.new(Redis.new) I18n.backend = Translator.setup_backend(I18n::Backend::Simple.new) + In Rails > 3.1 you should mount the translator Engine in config/routes.rb: mount Translator::Engine, :to => '/admin' # will provide a /admin/translations path @@ -24,18 +24,6 @@ You might also need to override default yaml parser by adding the line to Gemfil There also appear to be problems with i18n v0.6.1 (truncated translations), so you might need to force v0.6.0: gem 'i18n', '0.6.0' -=== For Redis: - -Create Gemfile and run "bundle": - - gem 'redis' - gem 'translator', :git => "git://github.com/amberbit/translator.git" - -Create initializer, for example config/initializers/translator.rb: - - Translator.current_store = Translator::RedisStore.new(Redis.new) - I18n.backend = Translator.setup_backend(I18n::Backend::Simple.new) - == Usage Remember to restart your server after running 'bundle' command. Translations engine is available under http://localhost:3000/translations and there is *no authorization* by default. @@ -105,8 +93,6 @@ As a developer, I want to override list of 'Framework Translations' with a custo As a user, I want to revert to default translation, loaded from YAML file, by clicking on 'Default' link. -Ad a user, I want to choose between Redis and MongoDB for translations storage. - == Future features: As a user, I want to have all strings I enter validated, based on values from *.yml files, so I cannot break the app with malformed translations (ie. with wrong number of parameters). diff --git a/app/backends/translator/mongo_store.rb b/app/backends/translator/mongo_store.rb deleted file mode 100644 index 07ffb78..0000000 --- a/app/backends/translator/mongo_store.rb +++ /dev/null @@ -1,43 +0,0 @@ -module Translator - class MongoStore - def initialize(collection) - @collection = collection - end - - def keys - @collection.distinct :_id - end - - def []=(key, value) - value = nil if value == '' || value.nil? - collection.update({:_id => key}, - {'$set' => {:value => ActiveSupport::JSON.encode(value)}}, - {:upsert => true, :safe => true}) - end - - def [](key) - if document = collection.find_one(:_id => key) - document["value"] - else - nil - end - end - - def destroy_entry(key) - @collection.remove({:_id => key}) - end - - def searchable? - true - end - - def clear_database - collection.drop - end - - private - - def collection; @collection; end - end -end - diff --git a/spec/acceptance/mongodb_spec.rb b/spec/acceptance/mongodb_spec.rb deleted file mode 100644 index c02f57d..0000000 --- a/spec/acceptance/mongodb_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -# encoding: UTF-8 -require File.dirname(__FILE__) + '/acceptance_helper' -require File.dirname(__FILE__) + '/translations_management' - -feature "Translations management with MongoDB", %q{ - In order to show user app in different translate - As a app admin - I want to -} do - - background do - conn = Mongo::Connection.new.db("translator_test").collection("translations") - Translator.current_store = Translator::MongoStore.new(conn) - I18n.backend = Translator.setup_backend(I18n::Backend::Simple.new) - Translator.current_store.clear_database - visit translations_path - end - - it_should_behave_like "translations_management" -end - diff --git a/spec/dummy/config/initializers/translator.rb b/spec/dummy/config/initializers/translator.rb index 929a75e..18e5d44 100644 --- a/spec/dummy/config/initializers/translator.rb +++ b/spec/dummy/config/initializers/translator.rb @@ -1,6 +1,4 @@ if Rails.env.development? - conn = Mongo::Connection.new.db("translator_test").collection("translations") -# Translator.current_store = Translator::MongoStore.new(conn) Translator.current_store = Translator::RedisStore.new(Redis.new) I18n.backend = Translator.setup_backend(I18n::Backend::Simple.new) diff --git a/spec/unit/mongo_store_spec.rb b/spec/unit/mongo_store_spec.rb deleted file mode 100644 index c752029..0000000 --- a/spec/unit/mongo_store_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -# encoding: UTF-8 -require 'spec_helper' - -describe Translator::MongoStore do - before :each do - conn = Mongo::Connection.new.db("translator_test").collection("translations") - @store = Translator::MongoStore.new(conn) - @store.clear_database - end - - it "should be possible to set translation value" do - @store["pl.hello.world"] = "Witaj, świecie!" - @store["pl.hello.world"].should eql("\"Witaj, \\u015bwiecie!\"") - end - - it "should list all keys" do - @store["pl.hello.world"] = "Witaj, świecie!" - @store["en.hello.world"] = "Hello, World!" - @store.keys.should include("pl.hello.world") - @store.keys.should include("en.hello.world") - end -end diff --git a/spec/unit/translator_spec.rb b/spec/unit/translator_spec.rb index 49384e2..d0697c4 100644 --- a/spec/unit/translator_spec.rb +++ b/spec/unit/translator_spec.rb @@ -2,8 +2,8 @@ describe Translator do before :all do - conn = Mongo::Connection.new.db("translator_test").collection("translations") - Translator.current_store = Translator::MongoStore.new(conn) + @store = Translator::RedisStore.new(Redis.new) + Translator.current_store = @store I18n.backend = Translator.setup_backend(I18n::Backend::Simple.new) end