tr8n 3.1.8 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. data/.gitignore +2 -1
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -1
  4. data/.watchr +18 -0
  5. data/Gemfile.lock +16 -10
  6. data/app/assets/images/tr8n/minus_node.png +0 -0
  7. data/app/assets/images/tr8n/pixel.gif +0 -0
  8. data/app/assets/images/tr8n/plus_node.png +0 -0
  9. data/app/assets/javascripts/tr8n/tr8n.js +1 -0
  10. data/app/assets/javascripts/tr8n/tr8n_client_sdk.js +581 -425
  11. data/app/assets/stylesheets/tr8n/layout.css.scss +1 -1
  12. data/app/assets/stylesheets/tr8n/tr8n.css.scss +20 -0
  13. data/app/controllers/tr8n/admin/base_controller.rb +4 -1
  14. data/app/controllers/tr8n/admin/clientsdk_controller.rb +1 -1
  15. data/app/controllers/tr8n/admin/metrics_controller.rb +30 -0
  16. data/app/controllers/tr8n/api/v1/base_controller.rb +12 -0
  17. data/app/controllers/tr8n/api/v1/language_controller.rb +7 -5
  18. data/app/controllers/tr8n/awards_controller.rb +1 -1
  19. data/app/controllers/tr8n/base_controller.rb +12 -6
  20. data/app/controllers/tr8n/dashboard_controller.rb +1 -1
  21. data/app/controllers/tr8n/forum_controller.rb +1 -1
  22. data/app/controllers/tr8n/glossary_controller.rb +1 -1
  23. data/app/controllers/tr8n/help_controller.rb +1 -1
  24. data/app/controllers/tr8n/phrases_controller.rb +1 -1
  25. data/app/controllers/tr8n/translator_controller.rb +8 -0
  26. data/app/helpers/tr8n/admin/base_helper.rb +1 -1
  27. data/app/helpers/tr8n/base_helper.rb +1 -1
  28. data/app/helpers/tr8n/dashboard_helper.rb +1 -1
  29. data/app/models/tr8n/base_filter.rb +1 -1
  30. data/app/models/tr8n/daily_language_metric.rb +1 -1
  31. data/app/models/tr8n/date_rule.rb +1 -1
  32. data/app/models/tr8n/gender_list_rule.rb +1 -1
  33. data/app/models/tr8n/gender_rule.rb +1 -1
  34. data/app/models/tr8n/glossary.rb +1 -1
  35. data/app/models/tr8n/glossary_filter.rb +1 -1
  36. data/app/models/tr8n/integration/ru/russian_gender_list_rule.rb +1 -1
  37. data/app/models/tr8n/integration/ru/russian_numeric_rule.rb +1 -1
  38. data/app/models/tr8n/ip_location.rb +1 -1
  39. data/app/models/tr8n/ip_location_filter.rb +1 -1
  40. data/app/models/tr8n/language.rb +19 -7
  41. data/app/models/tr8n/language_case.rb +1 -1
  42. data/app/models/tr8n/language_case_filter.rb +1 -1
  43. data/app/models/tr8n/language_case_rule.rb +1 -1
  44. data/app/models/tr8n/language_case_rule_filter.rb +1 -1
  45. data/app/models/tr8n/language_case_value_map.rb +1 -1
  46. data/app/models/tr8n/language_case_value_map_filter.rb +1 -1
  47. data/app/models/tr8n/language_filter.rb +1 -1
  48. data/app/models/tr8n/language_forum_abuse_report.rb +1 -1
  49. data/app/models/tr8n/language_forum_abuse_report_filter.rb +1 -1
  50. data/app/models/tr8n/language_forum_message.rb +1 -1
  51. data/app/models/tr8n/language_forum_message_filter.rb +1 -1
  52. data/app/models/tr8n/language_forum_topic.rb +1 -1
  53. data/app/models/tr8n/language_forum_topic_filter.rb +1 -1
  54. data/app/models/tr8n/language_metric.rb +1 -1
  55. data/app/models/tr8n/language_metric_filter.rb +1 -1
  56. data/app/models/tr8n/language_rule.rb +1 -1
  57. data/app/models/tr8n/language_rule_filter.rb +1 -1
  58. data/app/models/tr8n/language_user.rb +1 -1
  59. data/app/models/tr8n/language_user_filter.rb +1 -1
  60. data/app/models/tr8n/list_rule.rb +1 -1
  61. data/app/models/tr8n/monthly_language_metric.rb +1 -1
  62. data/app/models/tr8n/numeric_rule.rb +35 -28
  63. data/app/models/tr8n/sync_log.rb +1 -1
  64. data/app/models/tr8n/sync_log_filter.rb +1 -1
  65. data/app/models/tr8n/total_language_metric.rb +1 -1
  66. data/app/models/tr8n/translation.rb +4 -3
  67. data/app/models/tr8n/translation_domain.rb +11 -3
  68. data/app/models/tr8n/translation_domain_filter.rb +1 -1
  69. data/app/models/tr8n/translation_filter.rb +1 -1
  70. data/app/models/tr8n/translation_key.rb +73 -36
  71. data/app/models/tr8n/translation_key_comment.rb +1 -1
  72. data/app/models/tr8n/translation_key_comment_filter.rb +1 -1
  73. data/app/models/tr8n/translation_key_filter.rb +1 -1
  74. data/app/models/tr8n/translation_key_lock.rb +1 -1
  75. data/app/models/tr8n/translation_key_lock_filter.rb +1 -1
  76. data/app/models/tr8n/translation_key_source.rb +16 -5
  77. data/app/models/tr8n/translation_key_source_filter.rb +1 -1
  78. data/app/models/tr8n/translation_source.rb +12 -4
  79. data/app/models/tr8n/translation_source_filter.rb +1 -1
  80. data/app/models/tr8n/translation_source_language.rb +1 -1
  81. data/app/models/tr8n/translation_vote.rb +1 -1
  82. data/app/models/tr8n/translation_vote_filter.rb +1 -1
  83. data/app/models/tr8n/translator.rb +21 -5
  84. data/app/models/tr8n/translator_filter.rb +1 -1
  85. data/app/models/tr8n/translator_following.rb +1 -1
  86. data/app/models/tr8n/translator_following_filter.rb +1 -1
  87. data/app/models/tr8n/translator_log.rb +3 -3
  88. data/app/models/tr8n/translator_log_filter.rb +1 -1
  89. data/app/models/tr8n/translator_metric.rb +1 -1
  90. data/app/models/tr8n/translator_metric_filter.rb +1 -1
  91. data/app/models/tr8n/translator_report.rb +1 -1
  92. data/app/models/tr8n/translator_report_filter.rb +1 -1
  93. data/app/models/tr8n/value_rule.rb +1 -1
  94. data/app/views/tr8n/admin/clientsdk/index.html.erb +29 -29
  95. data/app/views/tr8n/admin/clientsdk/lb_samples.html.erb +1 -1
  96. data/app/views/tr8n/admin/metrics/_tabs.html.erb +22 -0
  97. data/app/views/tr8n/admin/metrics/index.html.erb +60 -0
  98. data/app/views/tr8n/common/_header.html.erb +3 -1
  99. data/app/views/tr8n/common/_language_selector.html.erb +4 -2
  100. data/app/views/tr8n/common/_scripts.html.erb +5 -0
  101. data/app/views/tr8n/common/_terms_of_service.html.erb +53 -0
  102. data/app/views/tr8n/help/credits.html.erb +4 -0
  103. data/app/views/tr8n/language/_select.html.erb +5 -1
  104. data/app/views/tr8n/translator/registration.html.erb +21 -0
  105. data/config/routes.rb +3 -1
  106. data/doc/classes.graffle +356 -7194
  107. data/lib/generators/tr8n/templates/config/tr8n/config.yml +9 -1
  108. data/lib/generators/tr8n/templates/config/tr8n/site/shortcuts.yml +1 -1
  109. data/lib/generators/tr8n/templates/config/tr8n/tokens/decorations.yml +4 -1
  110. data/lib/generators/tr8n/tr8n_generator.rb +1 -1
  111. data/lib/tasks/tr8n.rake +1 -1
  112. data/lib/tr8n.rb +23 -0
  113. data/lib/tr8n/active_dumper.rb +1 -1
  114. data/lib/tr8n/cache.rb +1 -8
  115. data/lib/tr8n/cache_adapters/memcached.rb +1 -1
  116. data/lib/tr8n/config.rb +37 -1
  117. data/lib/tr8n/dictionary.rb +1 -1
  118. data/lib/tr8n/engine.rb +4 -1
  119. data/lib/tr8n/exception.rb +1 -1
  120. data/lib/tr8n/extender.rb +1 -1
  121. data/lib/tr8n/extensions/action_controller_extension.rb +5 -4
  122. data/lib/tr8n/extensions/action_view_extension.rb +71 -20
  123. data/lib/tr8n/extensions/array_extension.rb +14 -1
  124. data/lib/tr8n/extensions/date_extension.rb +1 -1
  125. data/lib/tr8n/extensions/fixnum_extension.rb +1 -1
  126. data/lib/tr8n/extensions/hash_extension.rb +1 -1
  127. data/lib/tr8n/extensions/string_extension.rb +1 -1
  128. data/lib/tr8n/extensions/time_extension.rb +1 -1
  129. data/lib/tr8n/ip_address.rb +1 -1
  130. data/lib/tr8n/key_registration_exception.rb +1 -1
  131. data/lib/tr8n/keyboard_mapping.rb +1 -1
  132. data/lib/tr8n/logger.rb +1 -1
  133. data/lib/tr8n/railtie.rb +1 -1
  134. data/lib/tr8n/site_map.rb +1 -1
  135. data/lib/tr8n/site_map_section.rb +1 -1
  136. data/lib/tr8n/token.rb +1 -1
  137. data/lib/tr8n/token_exception.rb +1 -1
  138. data/lib/tr8n/tokenized_label.rb +2 -12
  139. data/lib/tr8n/tokens/data_token.rb +1 -1
  140. data/lib/tr8n/tokens/decoration_token.rb +1 -1
  141. data/lib/tr8n/tokens/hidden_token.rb +1 -1
  142. data/lib/tr8n/tokens/method_token.rb +1 -1
  143. data/lib/tr8n/tokens/transform_token.rb +1 -1
  144. data/lib/tr8n/version.rb +25 -1
  145. data/local/tr8n_server/app/models/user.rb +1 -0
  146. data/local/tr8n_server/config/environments/test.rb +1 -1
  147. data/local/tr8n_server/config/tr8n/config.yml +45 -39
  148. data/local/tr8n_server/config/tr8n/site/shortcuts.yml +1 -1
  149. data/local/tr8n_server/db/schema.rb +2 -0
  150. data/spec/controllers/awards_controller_spec.rb +22 -0
  151. data/spec/controllers/base_controller_spec.rb +6 -0
  152. data/spec/controllers/dashboard_controller_spec.rb +23 -0
  153. data/spec/controllers/forum_controller_spec.rb +23 -0
  154. data/spec/controllers/glossary_controller_spec.rb +22 -0
  155. data/spec/controllers/help_controller_spec.rb +22 -0
  156. data/spec/controllers/language_cases_controller_spec.rb +13 -0
  157. data/spec/controllers/language_controller_spec.rb +10 -0
  158. data/spec/controllers/phrases_controller_spec.rb +22 -0
  159. data/spec/controllers/translations_controller_spec.rb +23 -0
  160. data/spec/controllers/translator_controller_spec.rb +22 -0
  161. data/spec/lib/tokenized_label_spec.rb +42 -0
  162. data/spec/lib/tokens/data_token_spec.rb +49 -0
  163. data/spec/lib/tokens/decoration_token_spec.rb +49 -0
  164. data/spec/lib/tokens/hidden_token_spec.rb +53 -0
  165. data/spec/lib/tokens/method_token_spec.rb +61 -0
  166. data/spec/lib/tokens/transform_token_spec.rb +51 -0
  167. data/spec/models/tr8n/daily_language_metric_spec.rb +5 -0
  168. data/spec/models/tr8n/date_rule_spec.rb +5 -0
  169. data/spec/models/tr8n/gender_list_rule_spec.rb +5 -0
  170. data/spec/models/tr8n/gender_rule_spec.rb +141 -0
  171. data/spec/models/tr8n/glossary_spec.rb +5 -0
  172. data/spec/models/tr8n/ip_location_spec.rb +5 -0
  173. data/spec/models/tr8n/language_case_rule_spec.rb +5 -0
  174. data/spec/models/tr8n/language_case_spec.rb +5 -0
  175. data/spec/models/tr8n/language_case_value_map_spec.rb +5 -0
  176. data/spec/models/tr8n/language_forum_abuse_report_spec.rb +5 -0
  177. data/spec/models/tr8n/language_forum_message_spec.rb +5 -0
  178. data/spec/models/tr8n/language_forum_topic_spec.rb +5 -0
  179. data/spec/models/tr8n/language_metric_spec.rb +5 -0
  180. data/spec/models/tr8n/language_rule_spec.rb +5 -0
  181. data/spec/models/tr8n/language_spec.rb +79 -0
  182. data/spec/models/tr8n/language_user_spec.rb +5 -0
  183. data/spec/models/tr8n/list_rule_spec.rb +5 -0
  184. data/spec/models/tr8n/monthly_language_metric_spec.rb +5 -0
  185. data/spec/models/tr8n/numeric_rule_spec.rb +162 -0
  186. data/spec/models/tr8n/sync_log_spec.rb +5 -0
  187. data/spec/models/tr8n/total_language_metric_spec.rb +5 -0
  188. data/spec/models/tr8n/translation_domain_spec.rb +5 -0
  189. data/spec/models/tr8n/translation_key_comment_spec.rb +5 -0
  190. data/spec/models/tr8n/translation_key_lock_spec.rb +5 -0
  191. data/spec/models/tr8n/translation_key_source_spec.rb +5 -0
  192. data/spec/models/tr8n/translation_key_spec.rb +118 -0
  193. data/spec/models/tr8n/translation_source_language_spec.rb +5 -0
  194. data/spec/models/tr8n/translation_source_spec.rb +5 -0
  195. data/spec/models/tr8n/translation_spec.rb +5 -0
  196. data/spec/models/tr8n/translation_vote_spec.rb +5 -0
  197. data/spec/models/tr8n/translator_following_spec.rb +5 -0
  198. data/spec/models/tr8n/translator_log_spec.rb +5 -0
  199. data/spec/models/tr8n/translator_metric_spec.rb +5 -0
  200. data/spec/models/tr8n/translator_report_spec.rb +5 -0
  201. data/spec/models/tr8n/translator_spec.rb +140 -0
  202. data/spec/spec_helper.rb +26 -27
  203. data/tr8n.gemspec +3 -1
  204. metadata +173 -50
  205. data/local/tr8n_server/db/migrate/20110930041150_create_tr8n_tables.rb +0 -372
  206. data/spec/fake_app.rb +0 -50
  207. data/spec/lib/data_token_spec.rb +0 -26
  208. data/spec/lib/transform_token_spec.rb +0 -22
  209. data/spec/models/translation_key_spec.rb +0 -63
@@ -36,9 +36,12 @@ defaults:
36
36
 
37
37
  enable_language_cases: true # enables support for language cases
38
38
  enable_client_sdk: false # allows javascript to use tr8nProxy object
39
+ enable_browser_cache: false # caches translations in the browser
39
40
 
40
41
  enable_country_tracking: true # tracks and reports translator countries
41
42
 
43
+ enable_translator_tabs: true # enables translation tools tabs
44
+
42
45
  #############################################################################
43
46
  # Google translation suggestions is now a paid feature by Google.
44
47
  #
@@ -72,7 +75,9 @@ defaults:
72
75
  # translation. If the flag is set to false, then a user must be promoted to
73
76
  # be a translator in order to submit or vote on translations.
74
77
  #############################################################################
75
- open_registration_mode: true
78
+ open_registration_mode: true
79
+ enable_registration_disclaimer: false
80
+ registration_disclaimer_path: "/tr8n/common/terms_of_service"
76
81
 
77
82
  #############################################################################
78
83
  # Tr8n best run with caching enabled
@@ -194,6 +199,9 @@ defaults:
194
199
  enabled: true
195
200
  response_encoding: "json" # options: xml, json
196
201
  allow_key_registration: true
202
+ skip_before_filters: [] # filters from application controller
203
+ before_filters: [] # filters from application controller
204
+ after_filters: [] # filters from application controller
197
205
 
198
206
  #############################################################################
199
207
  # Translator Roles - manager level is set at 1000 and anything above
@@ -8,7 +8,7 @@ Ctrl+Shift+I:
8
8
 
9
9
  Ctrl+Shift+L:
10
10
  description: Shows/hides language selector
11
- script: "tr8nLanguageSelector.toggle();"
11
+ script: "tr8nLightbox.show('/tr8n/language/select?lightbox=true', {height:500, width:400});"
12
12
 
13
13
  Ctrl+Shift+A:
14
14
  description: Displays all available languages
@@ -13,4 +13,7 @@ i: "<i>{$0}</i>"
13
13
  link: "<a href='{$href}'>{$0}</a>"
14
14
  br: "<br>{$0}"
15
15
  div: "<div id='{$id}' class='{$class}' style='{$style}'>{$0}</div>"
16
- span: "<span id='{$id}' class='{$class}' style='{$style}'>{$0}</span>"
16
+ span: "<span id='{$id}' class='{$class}' style='{$style}'>{$0}</span>"
17
+ h1: "<h1>{$0}</h1>"
18
+ h2: "<h2>{$0}</h2>"
19
+ h3: "<h3>{$0}</h3>"
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,3 +1,26 @@
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
+
1
24
  require File.join(File.dirname(__FILE__), 'tr8n/railtie')
2
25
  require File.join(File.dirname(__FILE__), 'tr8n/engine')
3
26
 
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Justin Balthrop
2
+ # Copyright (c) 2010-2012 Justin Balthrop
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -149,12 +149,5 @@ module Tr8n
149
149
  end
150
150
  end
151
151
 
152
- def self.cache_key_source(translation_key, source_name)
153
- source_name ||= Tr8n::Config.current_source || 'Undefined'
154
- translation_source = Tr8n::TranslationSource.find_or_create(source_name)
155
- key_source = Tr8n::TranslationKeySource.find_or_create(translation_key, translation_source)
156
- key_source
157
- end
158
-
159
152
  end
160
153
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -261,6 +261,14 @@ module Tr8n
261
261
  def self.open_registration_mode?
262
262
  config[:open_registration_mode]
263
263
  end
264
+
265
+ def self.enable_registration_disclaimer?
266
+ config[:enable_registration_disclaimer]
267
+ end
268
+
269
+ def self.registration_disclaimer_path
270
+ config[:registration_disclaimer_path] || "/tr8n/common/terms_of_service"
271
+ end
264
272
 
265
273
  def self.enable_fallback_languages?
266
274
  config[:enable_fallback_languages]
@@ -282,6 +290,10 @@ module Tr8n
282
290
  config[:enable_country_tracking]
283
291
  end
284
292
 
293
+ def self.enable_translator_tabs?
294
+ config[:enable_translator_tabs]
295
+ end
296
+
285
297
  #########################################################
286
298
  # Config Sections
287
299
  def self.caching
@@ -744,6 +756,30 @@ module Tr8n
744
756
  config[:enable_client_sdk]
745
757
  end
746
758
 
759
+ def self.enable_browser_cache?
760
+ config[:enable_browser_cache]
761
+ end
762
+
763
+ def self.default_client_interval
764
+ 5000
765
+ end
766
+
767
+ def self.api_skip_before_filters
768
+ return [] unless api[:skip_before_filters]
769
+ @api_skip_before_filters ||= api[:skip_before_filters].collect{|filter| filter.to_sym}
770
+ end
771
+
772
+ def self.api_before_filters
773
+ return [] unless api[:before_filters]
774
+ @api_before_filters ||= api[:before_filters].collect{|filter| filter.to_sym}
775
+ end
776
+
777
+ def self.api_after_filters
778
+ return [] unless api[:after_filters]
779
+ @api_after_filters ||= api[:after_filters].collect{|filter| filter.to_sym}
780
+ end
781
+
782
+
747
783
  #########################################################
748
784
  # Sync Process
749
785
  #########################################################
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -24,5 +24,8 @@
24
24
  module Tr8n
25
25
  class Engine < Rails::Engine
26
26
  isolate_namespace Tr8n
27
+ config.generators do |g|
28
+ g.test_framework :rspec, :view_specs => false
29
+ end
27
30
  end
28
31
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Justin Balthrop
2
+ # Copyright (c) 2010-2012 Justin Balthrop
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -86,9 +86,7 @@ module Tr8n
86
86
  return user
87
87
  end
88
88
 
89
- user = eval(Tr8n::Config.current_user_method)
90
- user = nil if user.class.name != Tr8n::Config.user_class_name
91
- user
89
+ eval(Tr8n::Config.current_user_method)
92
90
  rescue
93
91
  Tr8n::Logger.error("Site user integration is enabled, but #{Tr8n::Config.current_user_method} method is not defined")
94
92
  Tr8n::Translator.new
@@ -115,6 +113,9 @@ module Tr8n
115
113
  # tr(label, {:desc => "", tokens => {}, ...})
116
114
  ############################################################
117
115
  def tr(label, desc = "", tokens = {}, options = {})
116
+
117
+ return label if label.tr8n_translated?
118
+
118
119
  if desc.is_a?(Hash)
119
120
  options = desc
120
121
  tokens = options[:tokens] || {}
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -26,38 +26,89 @@ module Tr8n
26
26
  extend ActiveSupport::Concern
27
27
  module InstanceMethods
28
28
 
29
- # generates translations json for client sdk
30
- def tr8n_translations_js_tag(opts = {})
29
+
30
+ def tr8n_default_client_source
31
+ "#{params[:controller]}/#{params[:action]}/JS"
32
+ end
33
+
34
+ # Creates a hash of translations for a page source(s) or a component(s)
35
+ def tr8n_translations_cache_tag(opts = {})
31
36
  html = []
32
- html << "<script>"
33
37
 
34
- var_name = opts[:id] || :tr8n_translations
38
+ opts[:translations_element_id] ||= :tr8n_translations
39
+ opts[:sources] ||= [tr8n_default_client_source]
40
+ client_sdk_var_name = opts[:client_var_name] || :tr8nProxy
35
41
 
36
- source_names = opts[:sources] || [opts[:source]]
37
- sources = Tr8n::TranslationSource.find(:all, :conditions => ["source in (?)", source_names])
38
- source_ids = sources.collect{|source| source.id}
42
+ if Tr8n::Config.enable_browser_cache? # translations are loaded through a script
39
43
 
40
- if source_ids.empty?
41
- conditions = ["1=2"]
42
- else
43
- conditions = ["(id in (select distinct(translation_key_id) from tr8n_translation_key_sources where translation_source_id in (?)))"]
44
- conditions << source_ids.uniq
45
- end
44
+ opts[:sources].each do |source_name|
45
+ source = Tr8n::TranslationSource.find_or_create(source_name, request.url)
46
+ js_source = "/tr8n/api/v1/language/translate.js?cache=true&sdk_jsvar=#{client_sdk_var_name}&source=#{CGI.escape(source_name)}&t=#{source.updated_at.to_i}"
47
+ html << "<script type='text/javascript' src='#{js_source}'></script>"
48
+ end
46
49
 
47
- translations = []
48
- Tr8n::TranslationKey.find(:all, :conditions => conditions).each_with_index do |tkey, index|
49
- trn = tkey.translate(Tr8n::Config.current_language, {}, {:api => true})
50
- translations << trn
50
+ else # translations are embedded right into the page
51
+
52
+ html << "<script>"
53
+ sources = Tr8n::TranslationSource.find(:all, :conditions => ["source in (?)", opts[:sources]])
54
+ source_ids = sources.collect{|source| source.id}
55
+
56
+ if source_ids.empty?
57
+ conditions = ["1=2"]
58
+ else
59
+ conditions = ["(id in (select distinct(translation_key_id) from tr8n_translation_key_sources where translation_source_id in (?)))"]
60
+ conditions << source_ids.uniq
61
+ end
62
+
63
+ translations = []
64
+ Tr8n::TranslationKey.find(:all, :conditions => conditions).each_with_index do |tkey, index|
65
+ trn = tkey.translate(Tr8n::Config.current_language, {}, {:api => true})
66
+ translations << trn
67
+ end
68
+
69
+ html << "#{client_sdk_var_name}.updateTranslations(#{translations.to_json});"
70
+ html << "</script>"
51
71
  end
72
+
73
+ html.join('').html_safe
74
+ end
75
+
76
+ # Creates an instance of tr8nProxy object
77
+ def tr8n_client_sdk_tag(opts = {})
78
+ opts[:default_source] ||= tr8n_default_client_source
79
+ opts[:scheduler_interval] ||= Tr8n::Config.default_client_interval
52
80
 
53
- html << "var #{var_name} = #{translations.to_json};"
81
+ opts[:enable_inline_translations] = (Tr8n::Config.current_user_is_translator? and Tr8n::Config.current_translator.enable_inline_translations? and (not Tr8n::Config.current_language.default?))
82
+ opts[:default_decorations] = Tr8n::Config.default_decoration_tokens
83
+ opts[:default_tokens] = Tr8n::Config.default_data_tokens
54
84
 
85
+ opts[:rules] = {
86
+ :number => Tr8n::Config.rules_engine[:numeric_rule], :gender => Tr8n::Config.rules_engine[:gender_rule],
87
+ :list => Tr8n::Config.rules_engine[:gender_list_rule], :date => Tr8n::Config.rules_engine[:date_rule]
88
+ }
89
+
90
+ client_var_name = opts[:client_var_name] || :tr8nProxy
91
+
92
+ html = [javascript_include_tag("tr8n/tr8n_client_sdk.js")]
93
+ html << "<script>"
94
+ html << " var #{client_var_name} = new Tr8n.Proxy(#{opts.to_json});"
95
+ html << " function reloadTranslations() { "
96
+ html << " #{client_var_name}.initTranslations(true); "
97
+ html << " } "
98
+ html << " function tr(label, description, tokens, options) { "
99
+ html << " return #{client_var_name}.tr(label, description, tokens, options); "
100
+ html << " } "
101
+ html << " function trl(label, description, tokens, options) { "
102
+ html << " return #{client_var_name}.trl(label, description, tokens, options); "
103
+ html << " } "
55
104
  html << "</script>"
56
- html.join('').html_safe
105
+ html.join("\n").html_safe
57
106
  end
58
107
 
59
108
  # translation functions
60
109
  def tr(label, desc = "", tokens = {}, options = {})
110
+ return label if label.tr8n_translated?
111
+
61
112
  if desc.is_a?(Hash)
62
113
  options = desc
63
114
  tokens = options[:tokens] || {}
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -38,6 +38,19 @@ class Array
38
38
  end
39
39
  end
40
40
 
41
+ # translate array values
42
+ def trl(description = "", options = {}, language = Tr8n::Config.current_language)
43
+ return [] if empty?
44
+
45
+ collect do |opt|
46
+ if opt.is_a?(String)
47
+ opt.trl(description, {}, options, language)
48
+ else
49
+ opt
50
+ end
51
+ end
52
+ end
53
+
41
54
  # creates a sentence with tr "and" joiner
42
55
  def tr_sentence(options = {}, language = Tr8n::Config.current_language)
43
56
  return "" if empty?
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Scott Steadman, Michael Berkovich
2
+ # Copyright (c) 2010-2012 Michael Berkovich, tr8n.net
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the