tr8n 3.1.8 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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
@@ -52,8 +52,13 @@ class Tr8n::NumericRule < Tr8n::LanguageRule
52
52
  token.send(Tr8n::Config.rules_engine[:numeric_rule][:object_method])
53
53
  end
54
54
 
55
- def number_token_value(token)
56
- self.class.number_token_value(token)
55
+ def self.sanitize_values(values)
56
+ return [] unless values
57
+ values.split(",").collect{|val| val.strip}
58
+ end
59
+
60
+ def self.humanize_values(values)
61
+ sanitize_values(values).join(", ")
57
62
  end
58
63
 
59
64
  # FORM: [object, singular, plural]
@@ -89,30 +94,7 @@ class Tr8n::NumericRule < Tr8n::LanguageRule
89
94
  args[0].pluralize
90
95
  end
91
96
 
92
- def evaluate(token)
93
- token_value = number_token_value(token)
94
- return false unless token_value
95
-
96
- result1 = evaluate_partial_rule(token_value.to_s, definition[:part1].to_sym, sanitize_values(definition[:value1]))
97
- return result1 unless definition[:multipart].to_s == "true"
98
-
99
- result2 = evaluate_partial_rule(token_value.to_s, definition[:part2].to_sym, sanitize_values(definition[:value2]))
100
- return (result1 or result2) if definition[:operator] == "or"
101
- return (result1 and result2)
102
-
103
- false
104
- end
105
-
106
- def sanitize_values(values)
107
- return [] unless values
108
- values.split(",").collect{|val| val.strip}
109
- end
110
-
111
- def humanize_values(values)
112
- sanitize_values(values).join(", ")
113
- end
114
-
115
- def evaluate_partial_rule(token_value, name, values)
97
+ def self.evaluate_rule_fragment(token_value, name, values)
116
98
  if name == :is
117
99
  return true if values.include?(token_value)
118
100
  return false
@@ -140,6 +122,32 @@ class Tr8n::NumericRule < Tr8n::LanguageRule
140
122
  false
141
123
  end
142
124
 
125
+ def evaluate(token)
126
+ token_value = number_token_value(token)
127
+ return false unless token_value
128
+
129
+ result1 = self.class.evaluate_rule_fragment(token_value.to_s, definition[:part1].to_sym, sanitize_values(definition[:value1]))
130
+ return result1 unless definition[:multipart].to_s == "true"
131
+
132
+ result2 = self.class.evaluate_rule_fragment(token_value.to_s, definition[:part2].to_sym, sanitize_values(definition[:value2]))
133
+ return (result1 or result2) if definition[:operator] == "or"
134
+ return (result1 and result2)
135
+
136
+ false
137
+ end
138
+
139
+ def number_token_value(token)
140
+ self.class.number_token_value(token)
141
+ end
142
+
143
+ def sanitize_values(values)
144
+ self.class.sanitize_values(values)
145
+ end
146
+
147
+ def humanize_values(values)
148
+ self.class.humanize_values(values)
149
+ end
150
+
143
151
  def to_hash
144
152
  { :type => self.class.dependency,
145
153
  :multipart => definition[:multipart], :operator => definition[:operator],
@@ -148,7 +156,6 @@ class Tr8n::NumericRule < Tr8n::LanguageRule
148
156
  }
149
157
  end
150
158
 
151
-
152
159
  # used to describe a context of a given translation
153
160
  def description
154
161
  rule_desc = describe_partial_rule(definition[:part1].to_sym, definition[:value1])
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich, tr8n.net
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, tr8n.net
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, tr8n.net
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, tr8n.net
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
@@ -307,7 +307,8 @@ class Tr8n::Translation < ActiveRecord::Base
307
307
  results = self.where("language_id = ?", language.id)
308
308
 
309
309
  # ensure that only allowed translations are visible
310
- results = results.where("translation_key_id in (select id from tr8n_translation_keys where level <= ?)", Tr8n::Config.current_translator.level)
310
+ allowed_level = Tr8n::Config.current_user_is_translator? ? Tr8n::Config.current_translator.level : 0
311
+ results = results.where("translation_key_id in (select id from tr8n_translation_keys where level <= ?)", allowed_level)
311
312
 
312
313
  results = results.where("label like ?", "%#{params[:search]}%") unless params[:search].blank?
313
314
 
@@ -320,7 +321,7 @@ class Tr8n::Translation < ActiveRecord::Base
320
321
  end
321
322
 
322
323
  if params[:submitted_by] == "me"
323
- results = results.where("translator_id = ?", Tr8n::Config.current_translator.id)
324
+ results = results.where("translator_id = ?", Tr8n::Config.current_user_is_translator? ? Tr8n::Config.current_translator.id : 0)
324
325
  end
325
326
 
326
327
  if params[:submitted_on] == "today"
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich, tr8n.net
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
@@ -34,15 +34,23 @@ class Tr8n::TranslationDomain < ActiveRecord::Base
34
34
  alias :key_sources :translation_key_sources
35
35
  alias :keys :translation_keys
36
36
 
37
+ def self.cache_key(domain_name)
38
+ "translation_domain_#{domain_name}"
39
+ end
40
+
41
+ def cache_key
42
+ self.class.cache_key(name)
43
+ end
44
+
37
45
  def self.find_or_create(url = nil)
38
46
  domain_name = URI.parse(url || 'localhost').host || 'localhost'
39
- Tr8n::Cache.fetch("translation_domain_#{domain_name}") do
47
+ Tr8n::Cache.fetch(cache_key(domain_name)) do
40
48
  find_by_name(domain_name) || create(:name => domain_name)
41
49
  end
42
50
  end
43
51
 
44
52
  def clear_cache
45
- Tr8n::Cache.delete("translation_domain_#{name}")
53
+ Tr8n::Cache.delete(cache_key)
46
54
  end
47
55
 
48
56
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich, tr8n.net
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, tr8n.net
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, tr8n.net
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
@@ -41,10 +41,19 @@ class Tr8n::TranslationKey < ActiveRecord::Base
41
41
  alias :domains :translation_domains
42
42
  alias :comments :translation_key_comments
43
43
 
44
+
45
+ def self.cache_key(key_hash)
46
+ "translation_key_#{key_hash}"
47
+ end
48
+
49
+ def cache_key
50
+ self.class.cache_key(key)
51
+ end
52
+
44
53
  def self.find_or_create(label, desc = "", options = {})
45
54
  key = generate_key(label, desc).to_s
46
55
 
47
- tkey = Tr8n::Cache.fetch("translation_key_#{key}") do
56
+ tkey = Tr8n::Cache.fetch(cache_key(key)) do
48
57
  existing_key = where(:key => key).first
49
58
 
50
59
  unless existing_key
@@ -61,31 +70,23 @@ class Tr8n::TranslationKey < ActiveRecord::Base
61
70
  end
62
71
  locale = options[:locale] || Tr8n::Config.block_options[:default_locale] || Tr8n::Config.default_locale
63
72
 
64
- existing_key ||= begin
65
- new_tkey = create(:key => key.to_s,
66
- :label => label,
67
- :description => desc,
68
- :locale => locale,
69
- :level => level,
70
- :admin => Tr8n::Config.block_options[:admin])
71
-
72
- unless options[:source].blank?
73
- # at the time of creation - mark the first source of the key
74
- Tr8n::TranslationKeySource.find_or_create(new_tkey, Tr8n::TranslationSource.find_or_create(options[:source], options[:url]))
75
- end
76
- new_tkey
77
- end
73
+ existing_key ||= create(:key => key.to_s,
74
+ :label => label,
75
+ :description => desc,
76
+ :locale => locale,
77
+ :level => level,
78
+ :admin => Tr8n::Config.block_options[:admin])
78
79
 
79
80
  # for backwards compatibility only
80
81
  mark_as_admin(existing_key, options)
81
82
  update_default_locale(existing_key, options)
82
83
 
83
84
  # mark each key as verified - but only if caching is enabled
85
+ # verification is used to cleanup unused keys
84
86
  existing_key.update_attributes(:verified_at => Time.now) if Tr8n::Config.enable_caching?
85
87
  existing_key
86
88
  end
87
89
 
88
- # for detailed tracking of all sources and caller stack - only needed for debugging - expensive
89
90
  track_source(tkey, options)
90
91
  tkey
91
92
  end
@@ -106,20 +107,31 @@ class Tr8n::TranslationKey < ActiveRecord::Base
106
107
  tkey.update_attributes(:locale => key_locale)
107
108
  end
108
109
 
109
- # used to create associations between the translation keys and source
110
- # primarely used for the site map and only needs to be enabled
111
- # for a short period of time on a single machine
112
- def self.track_source(tkey, options)
113
- # return unless Tr8n::Config.enable_key_source_tracking?
114
- # return if options[:source].blank?
110
+ # creates associations between the translation keys and sources
111
+ # used for the site map and javascript support
112
+ def self.track_source(translation_key, options)
115
113
 
116
- key_source = Tr8n::Cache.cache_key_source(tkey, options[:source] || Tr8n::Config.block_options[:source])
117
-
118
- return unless Tr8n::Config.enable_key_caller_tracking?
114
+ # key source tracking or client sdk must be enabled for this to work
115
+ return unless Tr8n::Config.enable_key_source_tracking? or Tr8n::Config.enable_client_sdk?
116
+
117
+ # source can be passed into an individual key, or as a block or fall back on the controller/action
118
+ source = options[:source] || Tr8n::Config.block_options[:source] || Tr8n::Config.current_source
119
+
120
+ # should never be blank
121
+ return if source.blank?
122
+
123
+ # each page or component is identified by a translation source
124
+ translation_source = Tr8n::TranslationSource.find_or_create(source, options[:url])
125
+
126
+ # each key is associated with one or more sources
127
+ translation_key_source = Tr8n::TranslationKeySource.find_or_create(translation_key, translation_source)
128
+
129
+ # for debugging purposes only - this will track the actual location of the key in the source
130
+ return unless Tr8n::Config.enable_key_caller_tracking?
119
131
  options[:caller] ||= caller
120
132
  options[:caller_key] = options[:caller].is_a?(Array) ? options[:caller].join(", ") : options[:caller].to_s
121
133
  options[:caller_key] = generate_key(options[:caller_key])
122
- key_source.update_details!(options)
134
+ translation_key_source.update_details!(options)
123
135
  end
124
136
 
125
137
  def self.generate_key(label, desc = "")
@@ -130,7 +142,7 @@ class Tr8n::TranslationKey < ActiveRecord::Base
130
142
 
131
143
  def reset_key!
132
144
  # remove old key from cache
133
- Tr8n::Cache.delete("translation_key_#{key}")
145
+ Tr8n::Cache.delete(cache_key)
134
146
  self.update_attributes(:key => self.class.generate_key(label, description))
135
147
  end
136
148
 
@@ -213,11 +225,14 @@ class Tr8n::TranslationKey < ActiveRecord::Base
213
225
  not locked?(language)
214
226
  end
215
227
 
216
- def followed?(translator = Tr8n::Config.current_translator)
228
+ def followed?(translator = nil)
229
+ translator ||= (Tr8n::Config.current_user_is_translator? ? Tr8n::Config.current_translator : nil)
230
+ return false unless translator
217
231
  Tr8n::TranslatorFollowing.following_for(translator, self)
218
232
  end
219
233
 
220
234
  def add_translation(label, rules = nil, language = Tr8n::Config.current_language, translator = Tr8n::Config.current_translator)
235
+ raise Tr8n::Exception.new("The translator is blocked and cannot submit translations") if translator.blocked?
221
236
  raise Tr8n::Exception.new("The sentence contains dirty words") unless language.clean_sentence?(label)
222
237
  translation = Tr8n::Translation.create(:translation_key => self, :language => language, :translator => translator, :label => label, :rules => rules)
223
238
  translation.vote!(translator, 1)
@@ -441,7 +456,7 @@ class Tr8n::TranslationKey < ActiveRecord::Base
441
456
  def default_decoration(language = Tr8n::Config.current_language, options = {})
442
457
  return label if Tr8n::Config.current_user_is_guest?
443
458
  return label unless Tr8n::Config.current_user_is_translator?
444
- return label unless translator_permitted_to_translate?
459
+ return label unless can_be_translated?
445
460
  return label if locked?(language)
446
461
 
447
462
  classes = ['tr8n_translatable']
@@ -463,8 +478,23 @@ class Tr8n::TranslationKey < ActiveRecord::Base
463
478
  super
464
479
  end
465
480
 
466
- def translator_permitted_to_translate?(translator = Tr8n::Config.current_translator)
467
- translator.level >= level
481
+ def can_be_translated?(translator = nil)
482
+ return false if locked?
483
+ translator ||= (Tr8n::Config.current_user_is_translator? ? Tr8n::Config.current_translator : nil)
484
+ translator_level = translator ? translator.level : 0
485
+ translator_level >= level
486
+ end
487
+
488
+ def can_be_locked?(translator = nil)
489
+ translator ||= (Tr8n::Config.current_user_is_translator? ? Tr8n::Config.current_translator : nil)
490
+ return false unless translator
491
+ translator.admin? or translator.manager?
492
+ end
493
+
494
+ def can_be_unlocked?(translator = nil)
495
+ translator ||= (Tr8n::Config.current_user_is_translator? ? Tr8n::Config.current_translator : nil)
496
+ return false unless translator
497
+ translator.admin? or translator.manager?
468
498
  end
469
499
 
470
500
  def decorate_translation(language, translated_label, translated = true, options = {})
@@ -472,7 +502,7 @@ class Tr8n::TranslationKey < ActiveRecord::Base
472
502
  return translated_label if Tr8n::Config.current_user_is_guest?
473
503
  return translated_label unless Tr8n::Config.current_user_is_translator?
474
504
  return translated_label unless Tr8n::Config.current_translator.enable_inline_translations?
475
- return translated_label unless translator_permitted_to_translate?
505
+ return translated_label unless can_be_translated?
476
506
  return translated_label if locked?(language)
477
507
  return translated_label if self.language == language
478
508
 
@@ -522,8 +552,15 @@ class Tr8n::TranslationKey < ActiveRecord::Base
522
552
  end
523
553
  end
524
554
 
555
+ def touch_sources
556
+ sources.each do |source|
557
+ source.touch
558
+ end
559
+ end
560
+
525
561
  def clear_cache
526
- Tr8n::Cache.delete("translation_key_#{key}")
562
+ Tr8n::Cache.delete(cache_key)
563
+ touch_sources
527
564
  end
528
565
 
529
566
  ###############################################################
@@ -643,7 +680,7 @@ class Tr8n::TranslationKey < ActiveRecord::Base
643
680
  end
644
681
 
645
682
  def self.for_params(params)
646
- results = self.where("tr8n_translation_keys.locale <> ? and (level is null or level <= ?)", Tr8n::Config.current_language.locale, Tr8n::Config.current_translator.level)
683
+ results = self.where("tr8n_translation_keys.locale <> ? and (level is null or level <= ?)", Tr8n::Config.current_language.locale, Tr8n::Config.current_user_is_translator? ? Tr8n::Config.current_translator.level : 0)
647
684
 
648
685
  if Tr8n::Config.enable_caching?
649
686
  results = results.where("verified_at is not null")
@@ -669,7 +706,7 @@ class Tr8n::TranslationKey < ActiveRecord::Base
669
706
  elsif params[:phrase_type] == "without"
670
707
  results = results.where("tr8n_translation_keys.id not in (select tr8n_translations.translation_key_id from tr8n_translations where tr8n_translations.language_id = ?)", Tr8n::Config.current_language.id)
671
708
 
672
- elsif params[:phrase_type] == "followed"
709
+ elsif params[:phrase_type] == "followed" and Tr8n::Config.current_user_is_translator?
673
710
  results = results.where("tr8n_translation_keys.id in (select tr8n_translator_following.object_id from tr8n_translator_following where tr8n_translator_following.translator_id = ? and tr8n_translator_following.object_type = ?)", Tr8n::Config.current_translator.id, 'Tr8n::TranslationKey')
674
711
  end
675
712