tr8n 3.2.1 → 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/Gemfile.lock +1 -1
  2. data/README.rdoc +19 -13
  3. data/app/controllers/tr8n/base_controller.rb +5 -1
  4. data/app/controllers/tr8n/language_controller.rb +2 -2
  5. data/app/models/tr8n/base_filter.rb +21 -0
  6. data/app/models/tr8n/daily_language_metric.rb +46 -22
  7. data/app/models/tr8n/date_rule.rb +41 -22
  8. data/app/models/tr8n/gender_list_rule.rb +41 -22
  9. data/app/models/tr8n/gender_rule.rb +41 -22
  10. data/app/models/tr8n/glossary.rb +44 -27
  11. data/app/models/tr8n/glossary_filter.rb +56 -33
  12. data/app/models/tr8n/ip_location.rb +23 -0
  13. data/app/models/tr8n/ip_location_filter.rb +57 -34
  14. data/app/models/tr8n/language.rb +28 -0
  15. data/app/models/tr8n/language_case.rb +27 -0
  16. data/app/models/tr8n/language_case_filter.rb +53 -30
  17. data/app/models/tr8n/language_case_rule.rb +24 -0
  18. data/app/models/tr8n/language_case_rule_filter.rb +53 -30
  19. data/app/models/tr8n/language_case_value_map.rb +24 -0
  20. data/app/models/tr8n/language_case_value_map_filter.rb +68 -45
  21. data/app/models/tr8n/language_filter.rb +23 -0
  22. data/app/models/tr8n/language_forum_abuse_report.rb +56 -33
  23. data/app/models/tr8n/language_forum_abuse_report_filter.rb +57 -34
  24. data/app/models/tr8n/language_forum_message.rb +69 -46
  25. data/app/models/tr8n/language_forum_message_filter.rb +61 -38
  26. data/app/models/tr8n/language_forum_topic.rb +62 -41
  27. data/app/models/tr8n/language_forum_topic_filter.rb +61 -38
  28. data/app/models/tr8n/language_metric.rb +28 -1
  29. data/app/models/tr8n/language_metric_filter.rb +23 -0
  30. data/app/models/tr8n/language_rule.rb +23 -0
  31. data/app/models/tr8n/language_rule_filter.rb +72 -49
  32. data/app/models/tr8n/language_user.rb +86 -61
  33. data/app/models/tr8n/language_user_filter.rb +57 -34
  34. data/app/models/tr8n/list_rule.rb +41 -22
  35. data/app/models/tr8n/monthly_language_metric.rb +46 -22
  36. data/app/models/tr8n/numeric_rule.rb +41 -22
  37. data/app/models/tr8n/sync_log.rb +21 -0
  38. data/app/models/tr8n/sync_log_filter.rb +48 -27
  39. data/app/models/tr8n/total_language_metric.rb +46 -22
  40. data/app/models/tr8n/translation.rb +28 -0
  41. data/app/models/tr8n/translation_domain.rb +76 -56
  42. data/app/models/tr8n/translation_domain_filter.rb +49 -26
  43. data/app/models/tr8n/translation_filter.rb +57 -34
  44. data/app/models/tr8n/translation_key.rb +44 -8
  45. data/app/models/tr8n/translation_key_comment.rb +60 -37
  46. data/app/models/tr8n/translation_key_comment_filter.rb +53 -30
  47. data/app/models/tr8n/translation_key_filter.rb +68 -45
  48. data/app/models/tr8n/translation_key_lock.rb +81 -59
  49. data/app/models/tr8n/translation_key_lock_filter.rb +53 -30
  50. data/app/models/tr8n/translation_key_source.rb +22 -0
  51. data/app/models/tr8n/translation_key_source_filter.rb +53 -30
  52. data/app/models/tr8n/translation_source.rb +20 -0
  53. data/app/models/tr8n/translation_source_filter.rb +53 -30
  54. data/app/models/tr8n/translation_source_language.rb +58 -39
  55. data/app/models/tr8n/translation_vote.rb +56 -35
  56. data/app/models/tr8n/translation_vote_filter.rb +57 -34
  57. data/app/models/tr8n/translator.rb +38 -0
  58. data/app/models/tr8n/translator_filter.rb +73 -50
  59. data/app/models/tr8n/translator_following.rb +58 -38
  60. data/app/models/tr8n/translator_following_filter.rb +57 -34
  61. data/app/models/tr8n/translator_log.rb +25 -0
  62. data/app/models/tr8n/translator_log_filter.rb +72 -49
  63. data/app/models/tr8n/translator_metric.rb +27 -0
  64. data/app/models/tr8n/translator_metric_filter.rb +61 -38
  65. data/app/models/tr8n/translator_report.rb +23 -0
  66. data/app/models/tr8n/translator_report_filter.rb +53 -30
  67. data/app/models/tr8n/value_rule.rb +41 -22
  68. data/bin/{tr8n.rb → tr8n} +0 -0
  69. data/file +94 -0
  70. data/lib/tasks/dev.rake +162 -0
  71. data/lib/tr8n/config.rb +5 -1
  72. data/lib/tr8n/version.rb +1 -1
  73. data/local/tr8n_server/config/tr8n/config.yml +2 -1
  74. data/local/tr8n_server/db/schema.rb +0 -2
  75. metadata +45 -43
@@ -20,11 +20,38 @@
20
20
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
+ #
24
+ #-- Tr8n::TranslationKey Schema Information
25
+ #
26
+ # Table name: tr8n_translation_keys
27
+ #
28
+ # id INTEGER not null, primary key
29
+ # type varchar(255)
30
+ # key varchar(255) not null
31
+ # label text not null
32
+ # description text
33
+ # verified_at datetime
34
+ # translation_count integer
35
+ # admin boolean
36
+ # locale varchar(255)
37
+ # level integer default = 0
38
+ # created_at datetime
39
+ # updated_at datetime
40
+ # synced_at datetime
41
+ #
42
+ # Indexes
43
+ #
44
+ # index_tr8n_translation_keys_on_key (key) UNIQUE
45
+ #
46
+ #++
23
47
 
24
48
  require 'digest/md5'
25
49
 
26
50
  class Tr8n::TranslationKey < ActiveRecord::Base
27
51
  set_table_name :tr8n_translation_keys
52
+
53
+ attr_accessible :key, :label, :description, :verified_at, :translation_count, :admin, :locale, :level, :synced_at
54
+
28
55
  after_save :clear_cache
29
56
  after_destroy :clear_cache
30
57
 
@@ -77,13 +104,9 @@ class Tr8n::TranslationKey < ActiveRecord::Base
77
104
  :level => level,
78
105
  :admin => Tr8n::Config.block_options[:admin])
79
106
 
80
- # for backwards compatibility only
81
107
  mark_as_admin(existing_key, options)
82
108
  update_default_locale(existing_key, options)
83
-
84
- # mark each key as verified - but only if caching is enabled
85
- # verification is used to cleanup unused keys
86
- existing_key.update_attributes(:verified_at => Time.now) if Tr8n::Config.enable_caching?
109
+ verify_key(existing_key, options)
87
110
  existing_key
88
111
  end
89
112
 
@@ -107,6 +130,14 @@ class Tr8n::TranslationKey < ActiveRecord::Base
107
130
  tkey.update_attributes(:locale => key_locale)
108
131
  end
109
132
 
133
+ # mark each key as verified - but only if caching is enabled
134
+ # verification is used to cleanup unused keys
135
+ def self.verify_key(tkey, options)
136
+ return unless Tr8n::Config.enable_key_verification?
137
+ existing_key.update_attributes(:verified_at => Time.now)
138
+
139
+ end
140
+
110
141
  # creates associations between the translation keys and sources
111
142
  # used for the site map and javascript support
112
143
  def self.track_source(translation_key, options = {})
@@ -135,9 +166,8 @@ class Tr8n::TranslationKey < ActiveRecord::Base
135
166
  options[:caller_key] = generate_key(options[:caller_key])
136
167
  translation_key_source.update_details!(options)
137
168
  end
138
-
139
169
  end
140
-
170
+
141
171
  def self.generate_key(label, desc = "")
142
172
  "#{Digest::MD5.hexdigest("#{label};;;#{desc}")}~"[0..-2]
143
173
  end
@@ -553,6 +583,12 @@ class Tr8n::TranslationKey < ActiveRecord::Base
553
583
  map
554
584
  end
555
585
  end
586
+
587
+ def touch_sources
588
+ sources.each do |source|
589
+ source.touch
590
+ end
591
+ end
556
592
 
557
593
  def touch_sources
558
594
  sources.each do |source|
@@ -561,7 +597,7 @@ class Tr8n::TranslationKey < ActiveRecord::Base
561
597
  end
562
598
 
563
599
  def clear_cache
564
- Tr8n::Cache.delete(cache_key)
600
+ # Tr8n::Cache.delete(cache_key)
565
601
  touch_sources
566
602
  end
567
603
 
@@ -1,37 +1,60 @@
1
- #--
2
- # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
23
-
24
- class Tr8n::TranslationKeyComment < ActiveRecord::Base
25
- set_table_name :tr8n_translation_key_comments
26
-
27
- belongs_to :language, :class_name => "Tr8n::Language"
28
- belongs_to :translator, :class_name => "Tr8n::Translator"
29
- belongs_to :translation_key, :class_name => "Tr8n::TranslationKey"
30
-
31
- alias :key :translation_key
32
-
33
- def toHTML
34
- return "" unless message
35
- message.gsub("\n", "<br>")
36
- end
37
- end
1
+ #--
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+ #
24
+ #-- Tr8n::TranslationKeyComment Schema Information
25
+ #
26
+ # Table name: tr8n_translation_key_comments
27
+ #
28
+ # id INTEGER not null, primary key
29
+ # language_id integer not null
30
+ # translation_key_id integer not null
31
+ # translator_id integer not null
32
+ # message text not null
33
+ # created_at datetime
34
+ # updated_at datetime
35
+ #
36
+ # Indexes
37
+ #
38
+ # tr8n_tkey_msgs_lang_id_tkey_id (language_id, translation_key_id)
39
+ # tr8n_tkey_msgs_translator_id (translator_id)
40
+ # tr8n_tkey_msgs_lang_id (language_id)
41
+ #
42
+ #++
43
+
44
+ class Tr8n::TranslationKeyComment < ActiveRecord::Base
45
+ set_table_name :tr8n_translation_key_comments
46
+
47
+ attr_accessible :language_id, :translation_key_id, :translator_id, :message
48
+ attr_accessible :language, :translator, :translation_key
49
+
50
+ belongs_to :language, :class_name => "Tr8n::Language"
51
+ belongs_to :translator, :class_name => "Tr8n::Translator"
52
+ belongs_to :translation_key, :class_name => "Tr8n::TranslationKey"
53
+
54
+ alias :key :translation_key
55
+
56
+ def toHTML
57
+ return "" unless message
58
+ message.gsub("\n", "<br>")
59
+ end
60
+ end
@@ -1,30 +1,53 @@
1
- #--
2
- # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
23
-
24
- class Tr8n::TranslationKeyCommentFilter < Tr8n::BaseFilter
25
-
26
- def inner_joins
27
- [:language, :translation_key, :translator]
28
- end
29
-
30
- end
1
+ #--
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+ #
24
+ #-- Tr8n::TranslationKeyCommentFilter Schema Information
25
+ #
26
+ # Table name: will_filter_filters
27
+ #
28
+ # id INTEGER not null, primary key
29
+ # type varchar(255)
30
+ # name varchar(255)
31
+ # data text
32
+ # user_id integer
33
+ # model_class_name varchar(255)
34
+ # created_at datetime
35
+ # updated_at datetime
36
+ #
37
+ # Indexes
38
+ #
39
+ # index_will_filter_filters_on_user_id (user_id)
40
+ #
41
+ #++
42
+
43
+ class Tr8n::TranslationKeyCommentFilter < Tr8n::BaseFilter
44
+
45
+ def model_class
46
+ Tr8n::TranslationKeyComment
47
+ end
48
+
49
+ def inner_joins
50
+ [:language, :translation_key, :translator]
51
+ end
52
+
53
+ end
@@ -1,45 +1,68 @@
1
- #--
2
- # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
23
-
24
- class Tr8n::TranslationKeyFilter < Tr8n::BaseFilter
25
-
26
- def default_filters
27
- super + [
28
- ["Verified Keys", "verified"],
29
- ["Unverified Keys", "unverified"]
30
- ]
31
- end
32
-
33
- def default_filter_conditions(key)
34
- super_conditions = super(key)
35
- return super_conditions if super_conditions
36
-
37
- case key
38
- when "verified"
39
- return [:verified_at, :is_provided]
40
- when "unverified"
41
- return [:verified_at, :is_not_provided]
42
- end
43
- end
44
-
45
- end
1
+ #--
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+ #
24
+ #-- Tr8n::TranslationKeyFilter Schema Information
25
+ #
26
+ # Table name: will_filter_filters
27
+ #
28
+ # id INTEGER not null, primary key
29
+ # type varchar(255)
30
+ # name varchar(255)
31
+ # data text
32
+ # user_id integer
33
+ # model_class_name varchar(255)
34
+ # created_at datetime
35
+ # updated_at datetime
36
+ #
37
+ # Indexes
38
+ #
39
+ # index_will_filter_filters_on_user_id (user_id)
40
+ #
41
+ #++
42
+
43
+ class Tr8n::TranslationKeyFilter < Tr8n::BaseFilter
44
+
45
+ def model_class
46
+ Tr8n::TranslationKey
47
+ end
48
+
49
+ def default_filters
50
+ super + [
51
+ ["Verified Keys", "verified"],
52
+ ["Unverified Keys", "unverified"]
53
+ ]
54
+ end
55
+
56
+ def default_filter_conditions(key)
57
+ super_conditions = super(key)
58
+ return super_conditions if super_conditions
59
+
60
+ case key
61
+ when "verified"
62
+ return [:verified_at, :is_provided]
63
+ when "unverified"
64
+ return [:verified_at, :is_not_provided]
65
+ end
66
+ end
67
+
68
+ end
@@ -1,59 +1,81 @@
1
- #--
2
- # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
23
-
24
- class Tr8n::TranslationKeyLock < ActiveRecord::Base
25
- set_table_name :tr8n_translation_key_locks
26
- after_save :clear_cache
27
- after_destroy :clear_cache
28
-
29
- belongs_to :translation_key, :class_name => "Tr8n::TranslationKey"
30
- belongs_to :language, :class_name => "Tr8n::Language"
31
- belongs_to :translator, :class_name => "Tr8n::Translator"
32
-
33
- alias :key :translation_key
34
-
35
- def self.find_or_create(translation_key, language)
36
- lock = where("translation_key_id = ? and language_id = ?", translation_key.id, language.id).first
37
- lock || create(:translation_key => translation_key, :language => language)
38
- end
39
-
40
- def self.for(translation_key, language)
41
- Tr8n::Cache.fetch("translation_key_lock_#{language.locale}_#{translation_key.key}") do
42
- find_or_create(translation_key, language)
43
- end
44
- end
45
-
46
- def lock!(translator = Tr8n::Config.current_translator)
47
- update_attributes(:locked => true, :translator => translator)
48
- translator.locked_translation_key!(translation_key, language)
49
- end
50
-
51
- def unlock!(translator = Tr8n::Config.current_translator)
52
- update_attributes(:locked => false, :translator => translator)
53
- translator.unlocked_translation_key!(translation_key, language)
54
- end
55
-
56
- def clear_cache
57
- Tr8n::Cache.delete("translation_key_lock_#{language.locale}_#{translation_key.key}")
58
- end
59
- end
1
+ #--
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+ #
24
+ #-- Tr8n::TranslationKeyLock Schema Information
25
+ #
26
+ # Table name: tr8n_translation_key_locks
27
+ #
28
+ # id INTEGER not null, primary key
29
+ # translation_key_id integer not null
30
+ # language_id integer not null
31
+ # translator_id integer
32
+ # locked boolean
33
+ # created_at datetime
34
+ # updated_at datetime
35
+ #
36
+ # Indexes
37
+ #
38
+ # tr8n_locks_key_id_lang_id (translation_key_id, language_id)
39
+ #
40
+ #++
41
+
42
+ class Tr8n::TranslationKeyLock < ActiveRecord::Base
43
+ set_table_name :tr8n_translation_key_locks
44
+
45
+ attr_accessible :translation_key_id, :language_id, :translator_id, :locked
46
+ attr_accessible :language, :translator, :translation_key
47
+
48
+ after_save :clear_cache
49
+ after_destroy :clear_cache
50
+
51
+ belongs_to :translation_key, :class_name => "Tr8n::TranslationKey"
52
+ belongs_to :language, :class_name => "Tr8n::Language"
53
+ belongs_to :translator, :class_name => "Tr8n::Translator"
54
+
55
+ alias :key :translation_key
56
+
57
+ def self.find_or_create(translation_key, language)
58
+ lock = where("translation_key_id = ? and language_id = ?", translation_key.id, language.id).first
59
+ lock || create(:translation_key => translation_key, :language => language)
60
+ end
61
+
62
+ def self.for(translation_key, language)
63
+ Tr8n::Cache.fetch("translation_key_lock_#{language.locale}_#{translation_key.key}") do
64
+ find_or_create(translation_key, language)
65
+ end
66
+ end
67
+
68
+ def lock!(translator = Tr8n::Config.current_translator)
69
+ update_attributes(:locked => true, :translator => translator)
70
+ translator.locked_translation_key!(translation_key, language)
71
+ end
72
+
73
+ def unlock!(translator = Tr8n::Config.current_translator)
74
+ update_attributes(:locked => false, :translator => translator)
75
+ translator.unlocked_translation_key!(translation_key, language)
76
+ end
77
+
78
+ def clear_cache
79
+ Tr8n::Cache.delete("translation_key_lock_#{language.locale}_#{translation_key.key}")
80
+ end
81
+ end