Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a finder method to find updated phrases

  • Loading branch information...
commit b2e5bda5b01d1e436af52184f9bdaf6cc7605416 1 parent d1c5c5e
@lifo lifo authored
Showing with 29 additions and 18 deletions.
  1. +29 −18 app/models/tolk/locale.rb
View
47 app/models/tolk/locale.rb
@@ -52,15 +52,11 @@ def dump_all(to = self.locales_config_path)
end
def phrases_with_translation(page = nil)
- result = Tolk::Phrase.paginate(:page => page, :conditions => { :'tolk_translations.locale_id' => self.id },
- :joins => :translations, :order => 'tolk_phrases.id ASC')
- Tolk::Phrase.send :preload_associations, result, :translations
-
- result.each do |phrase|
- phrase.translation = phrase.translations.for(self)
- end
+ find_phrases_with_translations(:'tolk_translations.primary_updated' => false)
+ end
- result
+ def phrases_with_updated_translation(page = nil)
+ find_phrases_with_translations(:'tolk_translations.primary_updated' => true)
end
def phrases_without_translation(page = nil)
@@ -97,16 +93,31 @@ def language_name
end
private
- def unsquish(string, value)
- if string.is_a?(String)
- unsquish(string.split("."), value)
- elsif string.size == 1
- { string.first => value }
- else
- key = string[0]
- rest = string[1..-1]
- { key => unsquish(rest, value) }
- end
+
+ def find_phrases_with_translations(conditions)
+ result = Tolk::Phrase.paginate(:page => page,
+ :conditions => { :'tolk_translations.locale_id' => self.id }.merge(conditions),
+ :joins => :translations, :order => 'tolk_phrases.id ASC')
+
+ Tolk::Phrase.send :preload_associations, result, :translations
+
+ result.each do |phrase|
+ phrase.translation = phrase.translations.for(self)
end
+
+ result
+ end
+
+ def unsquish(string, value)
+ if string.is_a?(String)
+ unsquish(string.split("."), value)
+ elsif string.size == 1
+ { string.first => value }
+ else
+ key = string[0]
+ rest = string[1..-1]
+ { key => unsquish(rest, value) }
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.