afalkear_translation_center 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +293 -0
  4. data/Rakefile +40 -0
  5. data/app/assets/images/translation_center/badr_it.png +0 -0
  6. data/app/assets/images/translation_center/loading.gif +0 -0
  7. data/app/assets/images/translation_center/translation_center_logo.png +0 -0
  8. data/app/assets/javascripts/translation_center/application.js +75 -0
  9. data/app/assets/javascripts/translation_center/bootstrap.js +2025 -0
  10. data/app/assets/javascripts/translation_center/categories.js +18 -0
  11. data/app/assets/javascripts/translation_center/center.js +55 -0
  12. data/app/assets/javascripts/translation_center/inspector.js.erb +59 -0
  13. data/app/assets/javascripts/translation_center/jquery-ui.js +14912 -0
  14. data/app/assets/javascripts/translation_center/jquery.jeditable.mini.js +38 -0
  15. data/app/assets/javascripts/translation_center/routes.js +15 -0
  16. data/app/assets/javascripts/translation_center/spin.min.js +1 -0
  17. data/app/assets/javascripts/translation_center/translation_keys.js +31 -0
  18. data/app/assets/javascripts/translation_center/translations.js +245 -0
  19. data/app/assets/stylesheets/translation_center/application.css +49 -0
  20. data/app/assets/stylesheets/translation_center/bootstrap.css +5894 -0
  21. data/app/assets/stylesheets/translation_center/categories.css +29 -0
  22. data/app/assets/stylesheets/translation_center/center.css +28 -0
  23. data/app/assets/stylesheets/translation_center/inspector.css +110 -0
  24. data/app/assets/stylesheets/translation_center/translation_keys.css +48 -0
  25. data/app/assets/stylesheets/translation_center/translations.css +32 -0
  26. data/app/controllers/translation_center/application_controller.rb +42 -0
  27. data/app/controllers/translation_center/categories_controller.rb +61 -0
  28. data/app/controllers/translation_center/center_controller.rb +67 -0
  29. data/app/controllers/translation_center/translation_keys_controller.rb +93 -0
  30. data/app/controllers/translation_center/translations_controller.rb +78 -0
  31. data/app/helpers/translation_center/application_helper.rb +58 -0
  32. data/app/helpers/translation_center/categories_helper.rb +4 -0
  33. data/app/helpers/translation_center/center_helper.rb +19 -0
  34. data/app/helpers/translation_center/translation_keys_helper.rb +4 -0
  35. data/app/helpers/translation_center/translations_helper.rb +4 -0
  36. data/app/models/translation_center/activity_query.rb +46 -0
  37. data/app/models/translation_center/category.rb +46 -0
  38. data/app/models/translation_center/translation.rb +94 -0
  39. data/app/models/translation_center/translation_key.rb +188 -0
  40. data/app/views/layouts/translation_center/application.html.haml +82 -0
  41. data/app/views/translation_center/categories/_category.html.haml +11 -0
  42. data/app/views/translation_center/categories/index.html.haml +7 -0
  43. data/app/views/translation_center/categories/keys.js.haml +10 -0
  44. data/app/views/translation_center/categories/show.html.haml +32 -0
  45. data/app/views/translation_center/categories/show.js.haml +7 -0
  46. data/app/views/translation_center/center/_activity.html.haml +49 -0
  47. data/app/views/translation_center/center/dashboard.html.haml +102 -0
  48. data/app/views/translation_center/center/manage.js.haml +3 -0
  49. data/app/views/translation_center/center/search_activity.js.haml +1 -0
  50. data/app/views/translation_center/errors/exception.html.haml +50 -0
  51. data/app/views/translation_center/translation_keys/_form.html.haml +18 -0
  52. data/app/views/translation_center/translation_keys/_show.html.haml +27 -0
  53. data/app/views/translation_center/translation_keys/_show_keys.html.haml +25 -0
  54. data/app/views/translation_center/translation_keys/_translation_keys.html.haml +16 -0
  55. data/app/views/translation_center/translation_keys/destroy.js.haml +4 -0
  56. data/app/views/translation_center/translation_keys/show.html.haml +8 -0
  57. data/app/views/translation_center/translation_keys/translations.js.haml +3 -0
  58. data/app/views/translation_center/translations/_accept_translation.html.haml +6 -0
  59. data/app/views/translation_center/translations/_index.html.haml +9 -0
  60. data/app/views/translation_center/translations/_search_results.html.haml +30 -0
  61. data/app/views/translation_center/translations/_show.html.haml +35 -0
  62. data/app/views/translation_center/translations/accept.js.haml +18 -0
  63. data/app/views/translation_center/translations/destroy.js.haml +11 -0
  64. data/app/views/translation_center/translations/search.html.haml +2 -0
  65. data/app/views/translation_center/translations/search.js.haml +1 -0
  66. data/app/views/translation_center/translations/unaccept.js.haml +9 -0
  67. data/app/views/translation_center/translations/unvote.js.haml +1 -0
  68. data/app/views/translation_center/translations/vote.js.haml +1 -0
  69. data/config/routes.rb +34 -0
  70. data/lib/afalkear_translation_center.rb +12 -0
  71. data/lib/generators/translation_center/USAGE +6 -0
  72. data/lib/generators/translation_center/add_lang/add_lang_generator.rb +31 -0
  73. data/lib/generators/translation_center/add_lang/templates/migrations/add_lang_status_translation_keys.rb +5 -0
  74. data/lib/generators/translation_center/install/install_generator.rb +38 -0
  75. data/lib/generators/translation_center/install/templates/assets/translation_center_logo.png +0 -0
  76. data/lib/generators/translation_center/install/templates/config/translation_center.yml +55 -0
  77. data/lib/generators/translation_center/install/templates/migrations/create_translation_center_categories.rb +9 -0
  78. data/lib/generators/translation_center/install/templates/migrations/create_translation_center_translation_keys.rb +16 -0
  79. data/lib/generators/translation_center/install/templates/migrations/create_translation_center_translations.rb +32 -0
  80. data/lib/tasks/translation_center.rake +56 -0
  81. data/lib/translation_center/acts_as_translator.rb +22 -0
  82. data/lib/translation_center/engine.rb +15 -0
  83. data/lib/translation_center/locale/en.yml +75 -0
  84. data/lib/translation_center/translation_helpers.rb +133 -0
  85. data/lib/translation_center/translations_transfer.rb +131 -0
  86. data/lib/translation_center/version.rb +3 -0
  87. data/test/dummy/README.rdoc +261 -0
  88. data/test/dummy/Rakefile +7 -0
  89. data/test/dummy/app/assets/images/translation_center_logo.png +0 -0
  90. data/test/dummy/app/assets/javascripts/application.js +16 -0
  91. data/test/dummy/app/assets/javascripts/articles.js +2 -0
  92. data/test/dummy/app/assets/stylesheets/application.css +14 -0
  93. data/test/dummy/app/assets/stylesheets/articles.css +4 -0
  94. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  95. data/test/dummy/app/controllers/application_controller.rb +6 -0
  96. data/test/dummy/app/controllers/articles_controller.rb +85 -0
  97. data/test/dummy/app/helpers/application_helper.rb +2 -0
  98. data/test/dummy/app/helpers/articles_helper.rb +2 -0
  99. data/test/dummy/app/models/article.rb +7 -0
  100. data/test/dummy/app/models/user.rb +16 -0
  101. data/test/dummy/app/views/articles/_form.html.haml +16 -0
  102. data/test/dummy/app/views/articles/edit.html.haml +7 -0
  103. data/test/dummy/app/views/articles/index.html.haml +32 -0
  104. data/test/dummy/app/views/articles/new.html.haml +5 -0
  105. data/test/dummy/app/views/articles/show.html.haml +14 -0
  106. data/test/dummy/app/views/layouts/application.html.erb +15 -0
  107. data/test/dummy/config/application.rb +60 -0
  108. data/test/dummy/config/boot.rb +10 -0
  109. data/test/dummy/config/database.yml +42 -0
  110. data/test/dummy/config/environment.rb +5 -0
  111. data/test/dummy/config/environments/development.rb +37 -0
  112. data/test/dummy/config/environments/production.rb +67 -0
  113. data/test/dummy/config/environments/test.rb +37 -0
  114. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  115. data/test/dummy/config/initializers/devise.rb +240 -0
  116. data/test/dummy/config/initializers/inflections.rb +15 -0
  117. data/test/dummy/config/initializers/mime_types.rb +5 -0
  118. data/test/dummy/config/initializers/secret_token.rb +7 -0
  119. data/test/dummy/config/initializers/session_store.rb +8 -0
  120. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  121. data/test/dummy/config/locales/ar.yml +6 -0
  122. data/test/dummy/config/locales/de.yml +2 -0
  123. data/test/dummy/config/locales/devise.en.yml +59 -0
  124. data/test/dummy/config/locales/en.yml +361 -0
  125. data/test/dummy/config/routes.rb +10 -0
  126. data/test/dummy/config/translation_center.yml +58 -0
  127. data/test/dummy/config.ru +4 -0
  128. data/test/dummy/db/migrate/20130410082611_devise_create_users.rb +46 -0
  129. data/test/dummy/db/migrate/20130410082701_create_articles.rb +10 -0
  130. data/test/dummy/db/migrate/20130410084711234392_create_translation_center_categories.rb +9 -0
  131. data/test/dummy/db/migrate/20130410084711235054_create_translation_center_translation_keys.rb +14 -0
  132. data/test/dummy/db/migrate/20130410084711235601_create_translation_center_translations.rb +13 -0
  133. data/test/dummy/db/migrate/20130410084711235602_install_audited.rb +28 -0
  134. data/test/dummy/db/migrate/20130410084711_acts_as_votable_migration.rb +23 -0
  135. data/test/dummy/db/migrate/20130410113111070575_add_de_status_translation_center_translation_keys.rb +5 -0
  136. data/test/dummy/db/migrate/20130417134539377014_add_ar_status_translation_center_translation_keys.rb +5 -0
  137. data/test/dummy/db/migrate/20130506103956_fix_translation_user_relation.rb +12 -0
  138. data/test/dummy/db/migrate/20130801102022_add_indicies.rb +8 -0
  139. data/test/dummy/db/schema.rb +110 -0
  140. data/test/dummy/log/test.log +0 -0
  141. data/test/dummy/public/404.html +26 -0
  142. data/test/dummy/public/422.html +26 -0
  143. data/test/dummy/public/500.html +25 -0
  144. data/test/dummy/public/favicon.ico +0 -0
  145. data/test/dummy/script/rails +6 -0
  146. data/test/dummy/spec/spec_helper.rb +38 -0
  147. data/test/dummy/test/fixtures/articles.yml +9 -0
  148. data/test/dummy/test/fixtures/posts.yml +9 -0
  149. data/test/dummy/test/fixtures/users.yml +11 -0
  150. data/test/dummy/test/functional/articles_controller_test.rb +49 -0
  151. data/test/dummy/test/functional/posts_controller_test.rb +49 -0
  152. data/test/dummy/test/unit/article_test.rb +7 -0
  153. data/test/dummy/test/unit/helpers/articles_helper_test.rb +4 -0
  154. data/test/dummy/test/unit/helpers/posts_helper_test.rb +4 -0
  155. data/test/dummy/test/unit/post_test.rb +7 -0
  156. data/test/dummy/test/unit/user_test.rb +7 -0
  157. data/test/fixtures/translation_center/categories.yml +7 -0
  158. data/test/fixtures/translation_center/translation_keys.yml +11 -0
  159. data/test/fixtures/translation_center/translations.yml +15 -0
  160. data/test/functional/translation_center/categories_controller_test.rb +51 -0
  161. data/test/functional/translation_center/center_controller_test.rb +9 -0
  162. data/test/functional/translation_center/translation_keys_controller_test.rb +51 -0
  163. data/test/functional/translation_center/translations_controller_test.rb +51 -0
  164. data/test/integration/navigation_test.rb +10 -0
  165. data/test/test_helper.rb +15 -0
  166. data/test/translation_center_test.rb +7 -0
  167. data/test/unit/helpers/translation_center/categories_helper_test.rb +6 -0
  168. data/test/unit/helpers/translation_center/center_helper_test.rb +6 -0
  169. data/test/unit/helpers/translation_center/translation_keys_helper_test.rb +6 -0
  170. data/test/unit/helpers/translation_center/translations_helper_test.rb +6 -0
  171. data/test/unit/translation_center/category_test.rb +9 -0
  172. data/test/unit/translation_center/translation_key_test.rb +9 -0
  173. data/test/unit/translation_center/translation_test.rb +9 -0
  174. metadata +418 -0
@@ -0,0 +1,29 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
5
+
6
+ .category {
7
+ display: block;
8
+ float: left;
9
+ width: 240px;
10
+ padding: 10px;
11
+ margin: 10px;
12
+ background-color: #E5F3FA;
13
+ -webkit-border-radius: 4px;
14
+ -moz-border-radius: 4px;
15
+ border-radius: 4px;
16
+ }
17
+
18
+ .category:hover {
19
+ text-decoration: none;
20
+ background-color: #D9EDF7;
21
+ }
22
+
23
+ #category {
24
+ margin-left: 0px;
25
+ }
26
+
27
+ .all_listing {
28
+ width: 1012px;
29
+ }
@@ -0,0 +1,28 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
5
+
6
+ #loading {
7
+ display: none;
8
+ }
9
+
10
+ .center_title {
11
+ font-size: 60%;
12
+ }
13
+
14
+ .search_field {
15
+ width: 130px !important;
16
+ }
17
+
18
+ #activity {
19
+ padding-top: 50px;
20
+ }
21
+
22
+ .ltr {
23
+ direction: ltr;
24
+ }
25
+
26
+ .rtl {
27
+ direction: rtl;
28
+ }
@@ -0,0 +1,110 @@
1
+ /*
2
+ *= require font-awesome
3
+ */
4
+
5
+ .tc-badge {
6
+ display: inline-block;
7
+ padding: 2px 4px;
8
+ font-size: 11.844px;
9
+ font-weight: bold;
10
+ line-height: 14px;
11
+ color: #ffffff;
12
+ text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
13
+ white-space: nowrap;
14
+ vertical-align: baseline;
15
+ background-color: #999999;
16
+ }
17
+
18
+ .label {
19
+ -webkit-border-radius: 3px;
20
+ -moz-border-radius: 3px;
21
+ border-radius: 3px;
22
+ }
23
+
24
+ .tc-badge {
25
+ padding-right: 9px;
26
+ padding-left: 9px;
27
+ -webkit-border-radius: 9px;
28
+ -moz-border-radius: 9px;
29
+ border-radius: 9px;
30
+ }
31
+
32
+ a.label:hover,
33
+ a.tc-badge:hover {
34
+ color: #ffffff;
35
+ text-decoration: none;
36
+ cursor: pointer;
37
+ }
38
+
39
+ .label-important,
40
+ .tc-badge-important {
41
+ background-color: #b94a48;
42
+ }
43
+
44
+ .label-important[href],
45
+ .tc-badge-important[href] {
46
+ background-color: #953b39;
47
+ }
48
+
49
+ .label-warning,
50
+ .tc-badge-warning {
51
+ background-color: #f89406;
52
+ }
53
+
54
+ .label-warning[href],
55
+ .tc-badge-warning[href] {
56
+ background-color: #c67605;
57
+ }
58
+
59
+ .label-success,
60
+ .tc-badge-success {
61
+ background-color: #468847;
62
+ }
63
+
64
+ .label-success[href],
65
+ .tc-badge-success[href] {
66
+ background-color: #356635;
67
+ }
68
+
69
+ .label-info,
70
+ .tc-badge-info {
71
+ background-color: #3a87ad;
72
+ }
73
+
74
+ .label-info[href],
75
+ .tc-badge-info[href] {
76
+ background-color: #2d6987;
77
+ }
78
+
79
+ .label-inverse,
80
+ .tc-badge-inverse {
81
+ background-color: #333333;
82
+ }
83
+
84
+ .label-inverse[href],
85
+ .tc-badge-inverse[href] {
86
+ background-color: #1a1a1a;
87
+ }
88
+
89
+ .btn .label,
90
+ .btn .tc-badge {
91
+ position: relative;
92
+ top: -1px;
93
+ }
94
+
95
+ .btn-mini .label,
96
+ .btn-mini .tc-badge {
97
+ top: 0;
98
+ }
99
+
100
+ .tc-inspector-link{
101
+ z-index:9999999;
102
+ opacity:0.5;
103
+ color:white !important;
104
+ position:absolute;
105
+ }
106
+
107
+ .tc-inspector-link:hover
108
+ {
109
+ opacity:1;
110
+ }
@@ -0,0 +1,48 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
5
+
6
+ .translation_keys_listing {
7
+ height: 410px;
8
+ overflow: auto;
9
+ width: 32%;
10
+ }
11
+
12
+ .translation_keys_listing small, .translation_keys_listing p {
13
+ word-break:break-all;
14
+ }
15
+
16
+ .translation_keys_listing small {
17
+ color: black;
18
+ }
19
+
20
+ .translation_keys_listing li {
21
+ overflow: hidden;
22
+ position: relative;
23
+ }
24
+
25
+ .translation_key_badge {
26
+ height: 80%;
27
+ width: 5px;
28
+ float: left;
29
+ position: absolute;
30
+ }
31
+
32
+ .translations_count {
33
+ margin-right: 5px;
34
+ }
35
+
36
+ .nav.nav-pills {
37
+ border-bottom: 1px solid #DDD;
38
+ padding-bottom: 10px;
39
+ }
40
+
41
+ .key_editable {
42
+ cursor: pointer;
43
+ }
44
+
45
+ .created_time {
46
+ font-size: 10px;
47
+ color: black;
48
+ }
@@ -0,0 +1,32 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
5
+
6
+ .translations_listing {
7
+ padding-left: 20px;
8
+ height: 410px;
9
+ width: 57%;
10
+ }
11
+
12
+ .translation_info {
13
+ }
14
+
15
+ .translation_box {
16
+ min-height: 100px !important;
17
+ padding-bottom: 9px;
18
+ }
19
+
20
+ .translations_vote {
21
+ margin-top: 13px;
22
+ margin-right: 12px;
23
+ text-align: center;
24
+ }
25
+
26
+ .translation_voting {
27
+ margin-top: 25px;
28
+ }
29
+
30
+ .votes_count {
31
+ margin-top: 13px;
32
+ }
@@ -0,0 +1,42 @@
1
+ module TranslationCenter
2
+ class ApplicationController < ActionController::Base
3
+ before_filter :translation_langs_filters
4
+ before_filter :authenticate_user!
5
+
6
+ if Rails.env.development?
7
+
8
+ # if an exception happens show the error page
9
+ rescue_from Exception do |exception|
10
+ @exception = exception
11
+ @path = request.path
12
+
13
+ render "translation_center/errors/exception"
14
+ end
15
+
16
+ end
17
+
18
+ # defaults
19
+ def translation_langs_filters
20
+ session[:current_filter] ||= 'untranslated'
21
+ session[:lang_from] ||= :en
22
+ session[:lang_to] = app_params[:lang_to] || session[:lang_to] || :en
23
+ I18n.locale = session[:lang_from] || I18n.default_locale
24
+ end
25
+
26
+ protected
27
+
28
+ def can_admin?
29
+ current_user.can_admin_translations?
30
+ end
31
+
32
+ def set_page_number
33
+ app_params[:page] ||= 1
34
+ @page = app_params[:page].to_i
35
+ end
36
+
37
+ def app_params
38
+ params.permit!
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,61 @@
1
+ require_dependency "translation_center/application_controller"
2
+
3
+ module TranslationCenter
4
+ class CategoriesController < ApplicationController
5
+ before_filter :can_admin?, only: [ :destroy ]
6
+ before_filter :set_page_number, except: :destroy
7
+
8
+ # GET /categories
9
+ # GET /categories.json
10
+ def index
11
+ @categories = Category.all
12
+
13
+ respond_to do |format|
14
+ format.html # index.html.erb
15
+ format.json { render json: @categories }
16
+ end
17
+ end
18
+
19
+ # GET /categories/1
20
+ # GET /categories/1.json
21
+ def show
22
+ @category = Category.find(category_params[:id])
23
+ session[:current_filter] = category_params[:filter] || session[:current_filter]
24
+ @keys = @category.send("#{session[:current_filter]}_keys", session[:lang_to]).offset(@page - 1).limit(TranslationKey::PER_PAGE)
25
+ @untranslated_keys_count = @category.untranslated_keys(session[:lang_to]).count
26
+ @translated_keys_count = @category.translated_keys(session[:lang_to]).count
27
+ @pending_keys_count = @category.pending_keys(session[:lang_to]).count
28
+ @all_keys_count = @untranslated_keys_count + @translated_keys_count + @pending_keys_count
29
+ respond_to do |format|
30
+ format.html # show.html.erb
31
+ format.js
32
+ end
33
+ end
34
+
35
+ # GET /categories/1/more_keys.js
36
+ def more_keys
37
+ @category = Category.find(category_params[:category_id])
38
+ @keys = @category.send("#{session[:current_filter]}_keys", session[:lang_to]).offset(@page - 1).limit(TranslationKey::PER_PAGE)
39
+ respond_to do |format|
40
+ format.js { render 'keys' }
41
+ end
42
+ end
43
+
44
+
45
+ # DELETE /categories/1
46
+ # DELETE /categories/1.json
47
+ def destroy
48
+ @category = Category.find(category_params[:id])
49
+ @category.destroy
50
+
51
+ respond_to do |format|
52
+ format.html { redirect_to categories_url }
53
+ format.json { head :no_content }
54
+ end
55
+ end
56
+
57
+ def category_params
58
+ params.permit!
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,67 @@
1
+ require_dependency "translation_center/application_controller"
2
+
3
+ module TranslationCenter
4
+ class CenterController < ApplicationController
5
+
6
+ before_filter :can_admin?, only: [ :dashboard, :search_activity, :manage ]
7
+ before_filter :set_page_number, only: [ :dashboard, :search_activity ]
8
+
9
+ # set language user translating from
10
+ def set_language_from
11
+ session[:lang_from] = center_params[:lang].to_sym
12
+ I18n.locale = session[:lang_from]
13
+ render nothing: true
14
+ end
15
+
16
+ # set language user translating to
17
+ def set_language_to
18
+ session[:lang_to] = center_params[:lang].to_sym
19
+
20
+ respond_to do |format|
21
+ format.html { redirect_to root_url }
22
+ format.js { render nothing: true }
23
+ end
24
+ end
25
+
26
+ def dashboard
27
+ @stats = TranslationKey.langs_stats
28
+ @langs = @stats.keys
29
+
30
+ # build an empty activity query
31
+ @activity_query = ActivityQuery.new(center_params[:activity_query])
32
+
33
+ #TODO perpage constant should be put somewhere else
34
+ @translations_changes = @activity_query.activities.offset(Translation::CHANGES_PER_PAGE * (@page - 1)).limit(Translation::CHANGES_PER_PAGE)
35
+ @total_pages = (@activity_query.activities.count / (Translation::CHANGES_PER_PAGE * 1.0)).ceil
36
+
37
+ respond_to do |format|
38
+ format.html
39
+ format.js { render 'search_activity' }
40
+ end
41
+ end
42
+
43
+ def search_activity
44
+ @translations_changes = ActivityQuery.new(center_params[:activity_query]).activities.offset(Translation::CHANGES_PER_PAGE * (@page - 1)).limit(Translation::CHANGES_PER_PAGE)
45
+ @total_pages = (ActivityQuery.new(center_params[:activity_query]).activities.count / (Translation::CHANGES_PER_PAGE * 1.0)).ceil
46
+
47
+ respond_to do |format|
48
+ format.js
49
+ end
50
+ end
51
+
52
+ def manage
53
+ # if locale is all then send no locale
54
+ locale = center_params[:locale] == 'all' ? nil : center_params[:locale]
55
+ TranslationCenter.send center_params[:manage_action], locale
56
+
57
+ respond_to do |format|
58
+ format.js
59
+ end
60
+ end
61
+
62
+ def center_params
63
+ params.permit!
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,93 @@
1
+ require_dependency "translation_center/application_controller"
2
+
3
+ module TranslationCenter
4
+ class TranslationKeysController < ApplicationController
5
+ before_filter :get_translation_key, except: [ :search ]
6
+ before_filter :can_admin?, only: [ :destroy, :update ]
7
+
8
+ # POST /translation_keys/1/update_translation.js
9
+ def update_translation
10
+ @translation = current_user.translation_for @translation_key, session[:lang_to]
11
+ @key_before_status = @translation_key.status(session[:lang_to])
12
+ respond_to do |format|
13
+ # only admin can edit accepted translations
14
+ if (current_user.can_admin_translations? || !@translation.accepted?) && !trans_params[:value].strip.blank?
15
+ # use yaml.load to handle arrays
16
+ @translation.update_attributes(value: YAML.load(trans_params[:value].strip), status: 'pending')
17
+ # translation added by admin is considered the accepted one as it is trusted
18
+ @translation.accept if current_user.can_admin_translations? && CONFIG['accept_admin_translations']
19
+ format.json {render json: { value: @translation.value, status: @translation.key.status(@translation.lang), key_before_status: @key_before_status } }
20
+ else
21
+ render nothing: true
22
+ end
23
+ end
24
+ end
25
+
26
+ # GET /translation_keys/translations
27
+ def translations
28
+ @translations = @translation_key.translations.in(session[:lang_to]).order('created_at DESC')
29
+
30
+ respond_to do |format|
31
+ format.js
32
+ end
33
+ end
34
+
35
+ # GET /translation_keys/1
36
+ def show
37
+ end
38
+
39
+ # PUT /translation_keys/1
40
+ # PUT /translation_keys/1.json
41
+ def update
42
+ trans_params[:value].strip!
43
+ @old_value = @translation_key.category.name
44
+ respond_to do |format|
45
+ if !trans_params[:value].blank? && @translation_key.update_attribute(:name, trans_params[:value])
46
+ format.json { render json: { new_value: @translation_key.name, new_category: @translation_key.category.name, old_category: @old_value, key_id: @translation_key.id } }
47
+ else
48
+ format.json { render json: @translation_key.errors, status: :unprocessable_entity }
49
+ end
50
+ end
51
+ end
52
+
53
+ # DELETE /translation_keys/1
54
+ # DELETE /translation_keys/1.json
55
+ def destroy
56
+ @category = @translation_key.category
57
+ @translation_key_id = @translation_key.id
58
+ @key_status = @translation_key.status(session[:lang_to])
59
+ @translation_key.destroy
60
+
61
+ respond_to do |format|
62
+ format.js
63
+ format.html {redirect_to @category, notice: I18n.t('translation_center.translation_keys.destroyed_successfully')}
64
+ end
65
+ end
66
+
67
+ # GET /translation_keys/search.json
68
+ def search
69
+ # if full name provided then get the key and redirect to it, otherwise return similar in json
70
+ if trans_params[:search_key_name].present?
71
+ @translation_key = TranslationKey.find_by_name(trans_params[:search_key_name])
72
+ else
73
+ @key_names = TranslationKey.where('name LIKE ?', "%#{trans_params[:query]}%")
74
+ end
75
+
76
+ respond_to do |format|
77
+ format.html { redirect_to @translation_key}
78
+ format.json { render json: @key_names.map(&:name) }
79
+ end
80
+ end
81
+
82
+ protected
83
+
84
+ def get_translation_key
85
+ id = trans_params[:translation_key_id] || trans_params[:id]
86
+ @translation_key = TranslationKey.find(id)
87
+ end
88
+
89
+ def trans_params
90
+ params.permit!
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,78 @@
1
+ require_dependency "translation_center/application_controller"
2
+
3
+ module TranslationCenter
4
+ class TranslationsController < ApplicationController
5
+ before_filter :can_admin?, only: [ :destroy, :accept, :unaccept ]
6
+ before_filter :set_page_number, only: [:search]
7
+
8
+ # POST /translations/1/vote
9
+ def vote
10
+ @translation = Translation.find(trans_params[:translation_id])
11
+ current_user.likes(@translation)
12
+ respond_to do |format|
13
+ format.js
14
+ end
15
+ end
16
+
17
+ # POST /translations/1/unvote
18
+ def unvote
19
+ @translation = Translation.find(trans_params[:translation_id])
20
+ current_user.unlike @translation
21
+ respond_to do |format|
22
+ format.js
23
+ end
24
+ end
25
+
26
+ # POST /translations/1/accept
27
+ def accept
28
+ @translation = Translation.find(trans_params[:translation_id])
29
+ @translation_already_accepted = @translation.key.accepted_in? session[:lang_to]
30
+ @translation.accept
31
+ @translation.save!
32
+ respond_to do |format|
33
+ format.js
34
+ end
35
+ end
36
+
37
+ # POST /translations/1/accept
38
+ def unaccept
39
+ @translation = Translation.find(trans_params[:translation_id])
40
+ @translation.unaccept
41
+ @translation.save!
42
+ respond_to do |format|
43
+ format.js
44
+ end
45
+ end
46
+
47
+ # DELETE /translations/1
48
+ # DELETE /translations/1.json
49
+ def destroy
50
+ @translation = Translation.find(trans_params[:id])
51
+ @translation_id = @translation.id
52
+ @translation_key_before_status = @translation.key.status session[:lang_to]
53
+ @translation_key_id = @translation.key.id
54
+ @translation.destroy
55
+ @translation_key_after_status = @translation.key.status session[:lang_to]
56
+
57
+ respond_to do |format|
58
+ format.js
59
+ end
60
+ end
61
+
62
+ def search
63
+ @result = Translation.where('value LIKE ?', "%#{trans_params[:translation_value]}%")
64
+ @translations = @result.offset(Translation::NUMBER_PER_PAGE * (@page - 1)).limit(Translation::NUMBER_PER_PAGE)
65
+ @total_pages = (@result.count / (Translation::NUMBER_PER_PAGE * 1.0)).ceil
66
+
67
+ respond_to do |format|
68
+ format.html
69
+ format.js
70
+ end
71
+ end
72
+
73
+ def trans_params
74
+ params.permit!
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,58 @@
1
+ module TranslationCenter
2
+ module ApplicationHelper
3
+
4
+ # get the current user the language translating from
5
+ def from_lang
6
+ session[:lang_from]
7
+ end
8
+
9
+ # get the current user the language translating to
10
+ def to_lang
11
+ session[:lang_to]
12
+ end
13
+
14
+ # returns the display name of the language
15
+ def language_name(lang)
16
+ TranslationCenter::CONFIG['lang'][lang.to_s]['name']
17
+ end
18
+
19
+ # returns the direction of the language rtl or ltr
20
+ def language_direction(lang)
21
+ TranslationCenter::CONFIG['lang'][lang.to_s]['direction']
22
+ end
23
+
24
+ # returns the current status filter for translation keys
25
+ def current_filter
26
+ session[:current_filter]
27
+ end
28
+
29
+ # returns true if the current filter is equal to the passed filter
30
+ def current_filter_is?(filter)
31
+ session[:current_filter] == filter
32
+ end
33
+
34
+ # returns true if the current user can admin translations
35
+ def translation_admin?
36
+ current_user.respond_to?(:can_admin_translations?) && current_user.can_admin_translations?
37
+ end
38
+
39
+ # returns formated date
40
+ def format_date(date)
41
+ date.strftime('%e %b %Y')
42
+ end
43
+
44
+ # returns path that changes the locale
45
+ def change_locale_url(locale)
46
+ current_path = "#{request.protocol}#{request.host_with_port}#{request.fullpath}"
47
+ if current_path.include?('lang_to=')
48
+ current_path.gsub("lang_to=#{session[:lang_to]}", "lang_to=#{locale.to_s}")
49
+ elsif current_path.include?('?')
50
+ "#{current_path}&lang_to=#{locale.to_s}"
51
+ else
52
+ "#{current_path}?lang_to=#{locale.to_s}"
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,4 @@
1
+ module TranslationCenter
2
+ module CategoriesHelper
3
+ end
4
+ end
@@ -0,0 +1,19 @@
1
+ module TranslationCenter
2
+ module CenterHelper
3
+
4
+ # returns a human readable view of the changes
5
+ def format_change(attribute, value)
6
+ # if value is an array then changed value
7
+ if value.is_a? Array
8
+ "<span class=\"label label-info\">#{attribute}</span> changed from <span class=\"label label-important\">#{value[0]}</span> to <span class=\"label label-success\">#{value[1]}</span>".html_safe
9
+ # else value is new
10
+ else
11
+ "<span class=\"label label-info\">#{attribute}</span> has new value <span class=\"label label-success\">#{value}</span>".html_safe
12
+ end
13
+ end
14
+
15
+ def translator_identifier_placeholder
16
+ "#{TranslationCenter::CONFIG['translator_type']} #{TranslationCenter::CONFIG['identifier_type']}".upcase
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,4 @@
1
+ module TranslationCenter
2
+ module TranslationKeysHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module TranslationCenter
2
+ module TranslationsHelper
3
+ end
4
+ end