1
1
module Tolk
2
2
class Locale < ActiveRecord ::Base
3
- set_table_name "tolk_locales"
4
3
5
4
MAPPING = {
6
5
'ar' => 'Arabic' ,
@@ -60,7 +59,8 @@ class Locale < ActiveRecord::Base
60
59
self . locales_config_path = "#{ Rails . root } /config/locales"
61
60
62
61
cattr_accessor :primary_locale_name
63
- self . primary_locale_name = I18n . default_locale . to_s
62
+ #self.primary_locale_name = I18n.default_locale.to_s
63
+ self . primary_locale_name = "en"
64
64
65
65
include Tolk ::Sync
66
66
include Tolk ::Import
@@ -112,29 +112,29 @@ def pluralization_data?(data)
112
112
end
113
113
114
114
def has_updated_translations?
115
- translations . count ( :conditions => { :'tolk_translations. primary_updated' => true } ) > 0
115
+ translations . where ( : primary_updated => true ) . count > 0
116
116
end
117
117
118
118
def phrases_with_translation ( page = nil )
119
- find_phrases_with_translations ( page , :'tolk_translations. primary_updated' => false )
119
+ find_phrases_with_translations ( page , :" #{ Tolk :: Translation . table_name } . primary_updated" => false )
120
120
end
121
121
122
122
def phrases_with_updated_translation ( page = nil )
123
- find_phrases_with_translations ( page , :'tolk_translations. primary_updated' => true )
123
+ find_phrases_with_translations ( page , :" #{ Tolk :: Translation . table_name } . primary_updated" => true )
124
124
end
125
125
126
126
def count_phrases_without_translation
127
- existing_ids = self . translations . all ( :select => 'tolk_translations. phrase_id' ) . map ( &:phrase_id ) . uniq
127
+ existing_ids = self . translations . all ( :select => " #{ Tolk :: Translation . table_name } . phrase_id" ) . map ( &:phrase_id ) . uniq
128
128
Tolk ::Phrase . count - existing_ids . count
129
129
end
130
130
131
131
def phrases_without_translation ( page = nil , options = { } )
132
- phrases = Tolk ::Phrase . scoped ( :order => 'tolk_phrases. key ASC' )
132
+ phrases = Tolk ::Phrase . scoped ( :order => " #{ Tolk :: Phrase . table_name } . key ASC" )
133
133
134
- existing_ids = self . translations . all ( :select => 'tolk_translations. phrase_id' ) . map ( &:phrase_id ) . uniq
135
- phrases = phrases . includes ( :translations => [ :locale ] ) . scoped ( :conditions => [ 'tolk_phrases. id NOT IN (?)' , existing_ids ] ) if existing_ids . present?
134
+ existing_ids = self . translations . all ( :select => " #{ Tolk :: Translation . table_name } . phrase_id" ) . map ( &:phrase_id ) . uniq
135
+ phrases = phrases . includes ( :translations => [ :locale ] ) . scoped ( :conditions => [ " #{ Tolk :: Phrase . table_name } . id NOT IN (?)" , existing_ids ] ) if existing_ids . present?
136
136
137
- result = phrases . paginate ( :page => page , :per_page => Tolk :: Phrase . per_page ) # page(page).per(Tolk::Phrase.per_page)
137
+ result = phrases . page ( page ) . per ( Tolk ::Phrase . per_page )
138
138
result
139
139
end
140
140
@@ -148,19 +148,19 @@ def search_phrases(query, scope, page = nil, options = {})
148
148
self . translations . containing_text ( query )
149
149
end
150
150
151
- phrases = Tolk ::Phrase . scoped ( :order => 'tolk_phrases. key ASC' )
152
- phrases = phrases . scoped ( :conditions => [ 'tolk_phrases. id IN(?)' , translations . map ( &:phrase_id ) . uniq ] )
151
+ phrases = Tolk ::Phrase . scoped ( :order => " #{ Tolk :: Phrase . table_name } . key ASC" )
152
+ phrases = phrases . scoped ( :conditions => [ " #{ Tolk :: Phrase . table_name } . id IN(?)" , translations . map ( &:phrase_id ) . uniq ] )
153
153
phrases . page ( page )
154
154
end
155
155
156
156
def search_phrases_without_translation ( query , page = nil , options = { } )
157
157
return phrases_without_translation ( page , options ) unless query . present?
158
158
159
- phrases = Tolk ::Phrase . scoped ( :order => 'tolk_phrases. key ASC' )
159
+ phrases = Tolk ::Phrase . scoped ( :order => " #{ Tolk :: Phrase . table_name } . key ASC" )
160
160
161
- found_translations_ids = Tolk ::Locale . primary_locale . translations . all ( :conditions => [ "tolk_translations. text LIKE ?" , "%#{ query } %" ] , :select => 'tolk_translations. phrase_id' ) . map ( &:phrase_id ) . uniq
162
- existing_ids = self . translations . all ( :select => 'tolk_translations. phrase_id' ) . map ( &:phrase_id ) . uniq
163
- phrases = phrases . scoped ( :conditions => [ 'tolk_phrases. id NOT IN (?) AND tolk_phrases. id IN(?)' , existing_ids , found_translations_ids ] ) if existing_ids . present?
161
+ found_translations_ids = Tolk ::Locale . primary_locale . translations . all ( :conditions => [ "#{ Tolk :: Translation . table_name } . text LIKE ?" , "%#{ query } %" ] , :select => " #{ Tolk :: Translation . table_name } . phrase_id" ) . map ( &:phrase_id ) . uniq
162
+ existing_ids = self . translations . all ( :select => " #{ Tolk :: Translation . table_name } . phrase_id" ) . map ( &:phrase_id ) . uniq
163
+ phrases = phrases . scoped ( :conditions => [ " #{ Tolk :: Phrase . table_name } . id NOT IN (?) AND #{ Tolk :: Phrase . table_name } . id IN(?)" , existing_ids , found_translations_ids ] ) if existing_ids . present?
164
164
165
165
result = phrases . page ( page )
166
166
result
@@ -218,8 +218,9 @@ def remove_invalid_translations_from_target
218
218
219
219
def find_phrases_with_translations ( page , conditions = { } )
220
220
result = Tolk ::Phrase . page ( page ) . find ( :all ,
221
- :conditions => { :'tolk_translations.locale_id' => self . id } . merge ( conditions ) ,
222
- :joins => :translations , :order => 'tolk_phrases.key ASC' )
221
+ :conditions => { :"#{ Tolk ::Translation . table_name } .locale_id" => self . id } . merge ( conditions ) ,
222
+ :joins => :translations , :order => "#{ Tolk ::Phrase . table_name } .key ASC" )
223
+
223
224
224
225
result . each do |phrase |
225
226
phrase . translation = phrase . translations . for ( self )
0 commit comments