Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed tolk to work on 3.1

  • Loading branch information...
commit b51ad4d168145856bf939de54998d7c2b641c6eb 1 parent 96e3ddc
@drogus drogus authored
View
8 Gemfile
@@ -1,13 +1,13 @@
source "http://rubygems.org"
-gem "rails", :git => "http://github.com/rails/rails.git"
-gem "arel", :git => "http://github.com/rails/arel.git"
+#gem "rails", "3.1.0.beta1"
+gem 'rails', :git => 'git://github.com/rails/rails.git'
-gem 'will_paginate', :git => 'https://github.com/JackDanger/will_paginate.git'
+gem 'kaminari', :git => "https://github.com/amatsuda/kaminari.git"
gem "ya2yaml"
+gem "capybara", :git => "https://github.com/jnicklas/capybara.git"
gem "factory_girl_rails"
-gem "capybara", ">= 0.3.9"
gem "sqlite3-ruby", :require => "sqlite3"
gem "mocha"
View
0  public/tolk/reset.css → app/assets/stylesheets/tolk/reset.css
File renamed without changes
View
0  public/tolk/screen.css → app/assets/stylesheets/tolk/screen.css
File renamed without changes
View
33 app/models/tolk/locale.rb
@@ -34,7 +34,7 @@ class Locale < ActiveRecord::Base
'nl' => 'Dutch',
'no' => 'Norwegian',
'pl' => 'Polish',
- 'pt-BR' => 'Portuguese (Brazilian)',
+ 'pt-br' => 'Portuguese (Brazilian)',
'pt-PT' => 'Portuguese (Portugal)',
'ro' => 'Romanian',
'ru' => 'Russian',
@@ -52,6 +52,7 @@ class Locale < ActiveRecord::Base
has_many :phrases, :through => :translations, :class_name => 'Tolk::Phrase'
has_many :translations, :class_name => 'Tolk::Translation', :dependent => :destroy
+
accepts_nested_attributes_for :translations, :reject_if => proc { |attributes| attributes['text'].blank? }
before_validation :remove_invalid_translations_from_target, :on => :update
@@ -133,8 +134,7 @@ def phrases_without_translation(page = nil, options = {})
existing_ids = self.translations.all(:select => 'tolk_translations.phrase_id').map(&:phrase_id).uniq
phrases = phrases.scoped(:conditions => ['tolk_phrases.id NOT IN (?)', existing_ids]) if existing_ids.present?
- result = phrases.paginate({:page => page, :per_page => Phrase.per_page}.merge(options))
- Tolk::Phrase.send :preload_associations, result, :translations
+ result = phrases.page(page).per(Tolk::Phrase.per_page)
result
end
@@ -148,22 +148,21 @@ def search_phrases(query, scope, page = nil, options = {})
self.translations.containing_text(query)
end
- phrases = Tolk::Phrase.scoped(:order => 'tolk_phrases.key ASC')
+ phrases = Tolk::Phrase.scoped(:order => 'tolk_phrases.key ASC')
phrases = phrases.scoped(:conditions => ['tolk_phrases.id IN(?)', translations.map(&:phrase_id).uniq])
- phrases.paginate({:page => page}.merge(options))
+ phrases.page(page)
end
-
+
def search_phrases_without_translation(query, page = nil, options = {})
return phrases_without_translation(page, options) unless query.present?
-
+
phrases = Tolk::Phrase.scoped(:order => 'tolk_phrases.key ASC')
found_translations_ids = Tolk::Locale.primary_locale.translations.all(:conditions => ["tolk_translations.text LIKE ?", "%#{query}%"], :select => 'tolk_translations.phrase_id').map(&:phrase_id).uniq
existing_ids = self.translations.all(:select => 'tolk_translations.phrase_id').map(&:phrase_id).uniq
phrases = phrases.scoped(:conditions => ['tolk_phrases.id NOT IN (?) AND tolk_phrases.id IN(?)', existing_ids, found_translations_ids]) if existing_ids.present?
- result = phrases.paginate({:page => page}.merge(options))
- Tolk::Phrase.send :preload_associations, result, :translations
+ result = phrases.page(page)
result
end
@@ -189,15 +188,15 @@ def language_name
MAPPING[self.name] || self.name
end
- def [](key)
+ def get(key)
if phrase = Tolk::Phrase.find_by_key(key)
- t = self.translations.find_by_phrase_id(phrase.id)
+ t = self.translations.where(:phrase_id => phrase.id).first
t.text if t
end
end
def translations_with_html
- translations = self.translations.all(:conditions => "tolk_translations.text LIKE '%>%' AND
+ translations = self.translations.all(:conditions => "tolk_translations.text LIKE '%>%' AND
tolk_translations.text LIKE '%<%' AND tolk_phrases.key NOT LIKE '%_html'", :joins => :phrase)
Translation.send :preload_associations, translations, :phrase
translations
@@ -206,9 +205,9 @@ def translations_with_html
private
def remove_invalid_translations_from_target
- self.translations.proxy_target.each do |t|
- unless t.valid?
- self.translations.proxy_target.delete(t)
+ self.translations.target.dup.each do |t|
+ unless t.valid?
+ self.translations.target.delete(t)
else
t.updated_at = Time.current # Silly hax to fool autosave into saving the record
end
@@ -218,12 +217,10 @@ def remove_invalid_translations_from_target
end
def find_phrases_with_translations(page, conditions = {})
- result = Tolk::Phrase.paginate(:page => page,
+ result = Tolk::Phrase.page(page).find(:all,
:conditions => { :'tolk_translations.locale_id' => self.id }.merge(conditions),
:joins => :translations, :order => 'tolk_phrases.key ASC')
- Tolk::Phrase.send :preload_associations, result, :translations
-
result.each do |phrase|
phrase.translation = phrase.translations.for(self)
end
View
6 app/models/tolk/translation.rb
@@ -4,7 +4,7 @@ class Translation < ActiveRecord::Base
scope :containing_text, lambda {|query| where("tolk_translations.text LIKE ?", "%#{query}%") }
- serialize :text, :previous_text
+ serialize :text
validates_presence_of :text, :if => proc {|r| r.primary.blank? && !r.explicit_nil }
validate :check_matching_variables, :if => proc { |tr| tr.primary_translation.present? }
@@ -12,6 +12,8 @@ class Translation < ActiveRecord::Base
belongs_to :phrase, :class_name => 'Tolk::Phrase'
belongs_to :locale, :class_name => 'Tolk::Locale'
+ validates_presence_of :locale_id
+
attr_accessor :force_set_primary_update
before_save :set_primary_updated
@@ -55,7 +57,7 @@ def value
def self.detect_variables(search_in)
case search_in
- when String then Set.new(search_in.scan(/\{\{(\w+)\}\}/).flatten + search_in.scan(/\%\{(\w+)\}/).flatten)
+ when String then Set.new(search_in.scan(/\{\{(\w+)\}\}/).flatten + search_in.scan(/\%\{(\w+)\}/).flatten)
when Array then search_in.inject(Set[]) { |carry, item| carry + detect_variables(item) }
when Hash then search_in.values.inject(Set[]) { |carry, item| carry + detect_variables(item) }
else Set[]
View
5 app/views/layouts/tolk/application.html.erb
@@ -12,7 +12,8 @@
<%= javascript_include_tag :defaults %>
<% end %>
- <%= stylesheet_link_tag "/tolk/reset", "/tolk/screen" %>
+ <%= stylesheet_link_tag "tolk/reset" %>
+ <%= stylesheet_link_tag "tolk/screen" %>
<%= yield :head %>
</head>
@@ -23,7 +24,7 @@
</div>
<%= yield %>
</div>
-
+
<script type="text/javascript">
$$('td textarea').each(function(element) {
element.setStyle({height: element.up('td').measure('height')+'px'});
View
2  app/views/tolk/locales/all.html.erb
@@ -53,7 +53,7 @@
<p><%= locale_form.submit "Save changes" %></p>
</div>
<div class="paginate">
- <%= will_paginate @phrases %>
+ <%= paginate @phrases %>
</div>
<% end %>
<% else %>
View
2  app/views/tolk/locales/show.html.erb
@@ -49,7 +49,7 @@
</div>
<% end %>
<div class="paginate">
- <%= will_paginate @phrases %>
+ <%= paginate @phrases %>
</div>
<% else %>
<p style="text-align: left">There aren't any missing or updated phrases that need translation.</p>
View
2  app/views/tolk/searches/show.html.erb
@@ -47,7 +47,7 @@
</div>
<% end %>
<div class="paginate">
- <%= will_paginate @phrases %>
+ <%= paginate @phrases %>
</div>
<% else %>
<p style="text-align: left">No search results.</p>
View
2  lib/tolk.rb
@@ -1,4 +1,4 @@
-require 'will_paginate'
+require 'kaminari'
require 'ya2yaml'
require 'tolk/engine'
require 'tolk/sync'
View
1  test/dummy/config/environments/development.rb
@@ -11,7 +11,6 @@
# Show full error reports and disable caching
config.consider_all_requests_local = true
- config.action_view.debug_rjs = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
View
3  test/dummy/log/development.log
@@ -616,3 +616,6 @@ Rendered /Users/drogus/.rvm/gems/ruby-1.9.2-p0@rails/bundler/gems/rails-7e4852f8
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
Tolk::Translation Load (0.4ms) SELECT "tolk_translations"."id" FROM "tolk_translations" WHERE ("tolk_translations"."phrase_id" IS NULL) AND ("tolk_translations"."locale_id" IS NULL) LIMIT 1
Tolk::Translation Load (0.3ms) SELECT "tolk_translations"."id" FROM "tolk_translations" WHERE ("tolk_translations"."phrase_id" IS NULL) AND ("tolk_translations"."locale_id" IS NULL) LIMIT 1
+ Tolk::Locale Load (0.2ms) SELECT "tolk_locales".* FROM "tolk_locales" LIMIT 1
+ Tolk::Phrase Load (0.2ms) SELECT "tolk_phrases".* FROM "tolk_phrases" WHERE "tolk_phrases"."key" = 'id' LIMIT 1
+ Tolk::Locale Load (0.2ms) SELECT "tolk_locales".* FROM "tolk_locales" LIMIT 1
View
1  test/test_helper.rb
@@ -2,6 +2,7 @@
ENV["RAILS_ENV"] = "test"
require File.expand_path("../dummy/config/environment.rb", __FILE__)
+ActiveRecord::IdentityMap.enabled = false
require "rails/test_help"
ActiveSupport::TestCase.fixture_path = Rails.root.to_s + "/../fixtures"
View
22 test/unit/format_test.rb
@@ -22,18 +22,18 @@ def setup
def test_all_formats_are_loaded_properly
# TODO : Investigate why the fuck does this test fail
# assert_equal 1, @en['number']
- assert_equal 'I am just a stupid string :(', @en['string']
- assert_equal [1, 2, 3], @en['number_array']
- assert_equal ['sun', 'moon'], @en['string_array']
+ assert_equal 'I am just a stupid string :(', @en.get('string')
+ assert_equal [1, 2, 3], @en.get('number_array')
+ assert_equal ['sun', 'moon'], @en.get('string_array')
end
def test_pluaralization
result = {'other' => 'Hello'}
- assert_equal result, @en['pluralization']
+ assert_equal result, @en.get('pluralization')
- assert ! @en['not_pluralization']
- assert_equal 'World', @en['not_pluralization.other']
- assert_equal 'fifo', @en['not_pluralization.lifo']
+ assert ! @en.get('not_pluralization')
+ assert_equal 'World', @en.get('not_pluralization.other')
+ assert_equal 'fifo', @en.get('not_pluralization.lifo')
end
# def test_specail_activerecord_keys_and_prefixes
@@ -60,7 +60,7 @@ def test_creating_translations_fails_on_mismatch_with_primary_translation
success.save!
assert_equal [1, 2], success.text
end
-
+
def test_creating_translations_fails_with_unmatching_variables
# Check that variable detection works correctly
assert_equal Set['hello', 'world'], ph('variables').translations.primary.variables
@@ -105,9 +105,9 @@ def test_bulk_translations_update_with_some_invalid_formats
@spanish.reload
- assert_equal 'spanish string', @spanish['string']
- assert_equal '2', @spanish['number']
- assert ! @spanish['string_array']
+ assert_equal 'spanish string', @spanish.get('string')
+ assert_equal '2', @spanish.get('number')
+ assert ! @spanish.get('string_array')
end
def test_bulk_update_saves_unchanged_record
View
6 test/unit/locale_test.rb
@@ -8,10 +8,10 @@ class LocaleTest < ActiveSupport::TestCase
end
test "turning locale with nested phrases into a hash" do
- assert_equal({ "en" => {
+ assert_equal({ "en" => {
"number"=>{"human"=>{"format"=>{"precision"=>1}}},
- "hello_world" => "Hello World",
- "nested" => {
+ "hello_world" => "Hello World",
+ "nested" => {
"hello_world" => "Nested Hello World",
"hello_country" => "Nested Hello Country"
}
Please sign in to comment.
Something went wrong with that request. Please try again.