diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f1eced4..bbec0a4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,50 +1,67 @@ class ApplicationController < ActionController::Base - protect_from_forgery with: :exception - - # Override build_footer method in ActiveAdmin::Views::Pages + protect_from_forgery with: :exception + + # Override build_footer method in ActiveAdmin::Views::Pages require 'active_admin_views_pages_base.rb' - - rescue_from CanCan::AccessDenied do |exception| - redirect_to root_url, :alert => exception.message - end - - after_filter :store_location - def store_location - # store last url - this is needed for post-login redirect to whatever the user last visited. - if (request.fullpath != "/users/sign_in" && \ - request.fullpath != "/users/sign_up" && \ - request.fullpath != "/users/password" && \ + rescue_from CanCan::AccessDenied do |exception| + redirect_to root_url, :alert => exception.message + end + + before_filter :set_locale + + after_filter :store_location + + def set_locale + # session data takes precedence + if session[:locale] + # if locales data is present in the session use it + I18n.locale = session[:locale] + elsif false # TODO + # if user has set preferred language use it + elsif false # TODO + # use user's organization language, keep in mine the "OTHER ORG" edge case which should use english + else + # just use the default language, line can be commented out, included just for clarity + # I18n.locale = config.i18n.default_locale + end + end + + def store_location + # store last url - this is needed for post-login redirect to whatever the user last visited. + if (request.fullpath != "/users/sign_in" && \ + request.fullpath != "/users/sign_up" && \ + request.fullpath != "/users/password" && \ request.fullpath != "/users/sign_up?nosplash=true" && \ - !request.xhr?) # don't store ajax calls - session[:previous_url] = request.fullpath - end - end + !request.xhr?) # don't store ajax calls + session[:previous_url] = request.fullpath + end + end - def after_sign_in_path_for(resource) - session[:previous_url] || root_path - end + def after_sign_in_path_for(resource) + session[:previous_url] || root_path + end - def after_sign_up_path_for(resource) - session[:previous_url] || root_path - end - - def after_sign_in_error_path_for(resource) - session[:previous_url] || root_path - end - - def after_sign_up_error_path_for(resource) - session[:previous_url] || root_path - end - - def authenticate_admin! - redirect_to root_path unless user_signed_in? && current_user.is_admin? - end + def after_sign_up_path_for(resource) + session[:previous_url] || root_path + end - def get_plan_list_columns - if user_signed_in? - @selected_columns = current_user.settings(:plan_list).columns - @all_columns = Settings::PlanList::ALL_COLUMNS - end - end + def after_sign_in_error_path_for(resource) + session[:previous_url] || root_path + end + + def after_sign_up_error_path_for(resource) + session[:previous_url] || root_path + end + + def authenticate_admin! + redirect_to root_path unless user_signed_in? && current_user.is_admin? + end + + def get_plan_list_columns + if user_signed_in? + @selected_columns = current_user.settings(:plan_list).columns + @all_columns = Settings::PlanList::ALL_COLUMNS + end + end end diff --git a/app/controllers/guidances_controller.rb b/app/controllers/guidances_controller.rb index a05db00..8718bb2 100644 --- a/app/controllers/guidances_controller.rb +++ b/app/controllers/guidances_controller.rb @@ -77,10 +77,10 @@ # updates phases, versions, sections and questions based on template selected dmptemplate = Dmptemplate.find(params[:dmptemplate_id]) # map to title and id for use in our options_for_select - @phases = dmptemplate.phases.map{|a| [a.title, a.id]}.insert(0, "Select a phase") - @versions = dmptemplate.versions.map{|s| [s.title, s.id]}.insert(0, "Select a version") - @sections = dmptemplate.sections.map{|s| [s.title, s.id]}.insert(0, "Select a section") - @questions = dmptemplate.questions.map{|s| [s.text, s.id]}.insert(0, "Select a question") + @phases = dmptemplate.phases.map{|a| [a.title, a.id]}.insert(0, I18n.t('helpers.select_phase')) + @versions = dmptemplate.versions.map{|s| [s.title, s.id]}.insert(0, I18n.t('helpers.select_version')) + @sections = dmptemplate.sections.map{|s| [s.title, s.id]}.insert(0, I18n.t('helpers.select_section')) + @questions = dmptemplate.questions.map{|s| [s.text, s.id]}.insert(0, I18n.t('helpers.select_question')) end @@ -88,23 +88,23 @@ # updates versions, sections and questions based on phase selected phase = Phase.find(params[:phase_id]) # map to name and id for use in our options_for_select - @versions = phase.versions.map{|s| [s.title, s.id]}.insert(0, "Select a version") - @sections = phase.sections.map{|s| [s.title, s.id]}.insert(0, "Select a section") - @questions = phase.questions.map{|s| [s.text, s.id]}.insert(0, "Select a question") + @versions = phase.versions.map{|s| [s.title, s.id]}.insert(0, I18n.t('helpers.select_version')) + @sections = phase.sections.map{|s| [s.title, s.id]}.insert(0, I18n.t('helpers.select_section')) + @questions = phase.questions.map{|s| [s.text, s.id]}.insert(0, I18n.t('helpers.select_question')) end def update_sections # updates sections and questions based on version selected version = Version.find(params[:version_id]) # map to name and id for use in our options_for_select - @sections = version.sections.map{|s| [s.title, s.id]}.insert(0, "Select a section") - @questions = version.questions.map{|s| [s.text, s.id]}.insert(0, "Select a question") + @sections = version.sections.map{|s| [s.title, s.id]}.insert(0, I18n.t('helpers.select_section')) + @questions = version.questions.map{|s| [s.text, s.id]}.insert(0, I18n.t('helpers.select_question')) end def update_questions # updates songs based on artist selected section = Section.find(params[:section_id]) - @questions = section.questions.map{|s| [s.text, s.id]}.insert(0, "Select a question") + @questions = section.questions.map{|s| [s.text, s.id]}.insert(0, I18n.t('helpers.select_question')) end diff --git a/app/controllers/locales_controller.rb b/app/controllers/locales_controller.rb new file mode 100644 index 0000000..72f5aed --- /dev/null +++ b/app/controllers/locales_controller.rb @@ -0,0 +1,10 @@ +class LocalesController < ApplicationController + + def change_session_locale + if params[:locale] + session[:locale] = params[:locale] + redirect_to :back + end + end + +end \ No newline at end of file diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a2ab8cc..a860980 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -6,7 +6,7 @@ def index if user_signed_in? then if (current_user.shibboleth_id.nil? || current_user.shibboleth_id.length == 0) && !cookies[:show_shib_link].nil? && cookies[:show_shib_link] == "show_shib_link" then - flash.notice = "Would you like to #{view_context.link_to 'link your DMPonline account to your institutional credentials?', user_omniauth_shibboleth_path}".html_safe + flash.notice = "Would you like to #{view_context.link_to I18n.t('helpers.shibboleth_to_link_text'), user_omniauth_shibboleth_path}".html_safe end @projects = current_user.projects.filter(params[:filter]) diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 4da5c9b..e6e8dc0 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -1,19 +1,19 @@ class UserMailer < ActionMailer::Base - default from: 'info@dcc.ac.uk' + default from: I18n.t('helpers.main_email.from') def sharing_notification(project_group) @project_group = project_group - mail(to: @project_group.user.email, subject: "You have been given access to a Data Management Plan") + mail(to: @project_group.user.email, subject: I18n.t('helpers.main_email.access_given')) end def permissions_change_notification(project_group) @project_group = project_group - mail(to: @project_group.user.email, subject: "DMP permissions changed") + mail(to: @project_group.user.email, subject: I18n.t('helpers.main_email.permission_changed')) end def project_access_removed_notification(user, project) @user = user @project = project - mail(to: @user.email, subject: "DMP access removed") + mail(to: @user.email, subject: I18n.t('helpers.main_email.access_removed')) end end \ No newline at end of file diff --git a/app/models/plan.rb b/app/models/plan.rb index e2989a3..70510fa 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -43,7 +43,7 @@ if !self.version.nil? && !self.version.phase.nil? && !self.version.phase.title? then return self.version.phase.title else - return "DMP title" + return I18n.t('tool_title2') end else return self.settings(:export).title diff --git a/app/models/question.rb b/app/models/question.rb index be97f38..f181719 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -72,7 +72,7 @@ GuidanceGroup.where("organisation_id = ?", org_admin.id).each do |group| group.guidances.each do |g| g.themes.where("id IN (?)", theme_ids).each do |gg| - guidances["#{group.name} guidance on #{gg.title}"] = g + guidances["#{group.name} " + I18n.t('admin.guidance_lowercase_on') + " #{gg.title}"] = g end end end @@ -81,7 +81,7 @@ question.guidances.each do |g_by_q| g_by_q.guidance_groups.each do |group| if group.organisation == org_admin - guidances["#{group.name} guidance"] = g_by_q + guidances["#{group.name} " + I18n.t('admin.guidance_lowercase')] = g_by_q end end end diff --git a/app/views/contact_us/contacts/new.html.erb b/app/views/contact_us/contacts/new.html.erb index fccdff6..7829d7a 100644 --- a/app/views/contact_us/contacts/new.html.erb +++ b/app/views/contact_us/contacts/new.html.erb @@ -20,7 +20,7 @@ <% if ContactUs.require_name %>
| <%= t('org_admin.guidance_group.name_label') %> | -
- <%= f.text_field :name,
- :as => :string,
- :class => 'text_field'%>
+
+
+ <%= form_for(@guidance_group, :url => admin_update_guidance_group_path(@guidance_group), :html => {:method => :put}) do |f| %>
-
-
- <%= link_to( image_tag('help_button.png'), '#', :class => 'guidance_group_title_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance_group.title_help_text_html'))%>
-
- |
-
| <%= t('org_admin.guidance.template') %> | -
- <% if @guidance_group.dmptemplate_ids == [] then %>
- <% default_select = "" %>
- <%else%>
- <% default_select = @guidance_group.dmptemplate_ids %>
- <%end%>
- <%= f.select :dmptemplate_ids, options_for_select(
- [['All templates', ""]].concat( Dmptemplate.funders_and_own_templates(current_user.organisation_id).collect{ |g| [g.title, g.id] }), :selected => default_select ),{} ,
- {:prompt => false , :multiple => true}%>
-
-
- <%= link_to( image_tag('help_button.png'), '#', :class => 'guidance_group_template_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance_group.template_help_text_html'))%>
-
-
- |
-
| <%= t('org_admin.guidance_group.published') %> | -
- <%= f.check_box :published %>
-
-
-
-
- |
-
| <%= t('org_admin.guidance_group.subset') %> | -
- <%= f.check_box :optional_subset %> <%= t('org_admin.guidance_group.subset_eg') %>
-
-
- <%= link_to( image_tag('help_button.png'), '#', :class => 'guidance_group_subset_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance_group.subset_option_help_text'))%>
-
- |
-
| <%= t('org_admin.guidance_group.name_label') %> | +
+
+ <%= f.text_field :name,
+ :as => :string,
+ :class => 'text_field' %>
+
+
+
+ <%= link_to(image_tag('help_button.png'), '#', :class => 'guidance_group_title_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance_group.title_help_text_html')) %>
+
+ |
+
| <%= t('org_admin.guidance.template') %> | +
+
+ <% if @guidance_group.dmptemplate_ids == [] then %>
+ <% default_select = "" %>
+ <% else %>
+ <% default_select = @guidance_group.dmptemplate_ids %>
+ <% end %>
+ <%= f.select :dmptemplate_ids, options_for_select(
+ [['All templates', ""]].concat(Dmptemplate.funders_and_own_templates(current_user.organisation_id).collect { |g| [g.title, g.id] }), :selected => default_select), {},
+ {:prompt => false, :multiple => true} %>
+
+
+ <%= link_to(image_tag('help_button.png'), '#', :class => 'guidance_group_template_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance_group.template_help_text_html')) %>
+
+
+ |
+
| <%= t('org_admin.templates.published_label') %> | +
+
+ <%= f.check_box :published %>
+
+
+
+
+ |
+
| <%= t('org_admin.guidance_group.subset') %> | +
+
+ <%= f.check_box :optional_subset %> <%= t('org_admin.guidance_group.subset_eg') %>
+
+
+ <%= link_to(image_tag('help_button.png'), '#', :class => 'guidance_group_subset_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance_group.subset_option_help_text')) %>
+
+ |
+
| <%= t("org_admin.guidance.name_label") %> | +<%= t('org_admin.guidance_group.name_label') %> |
<%= f.text_field :name,
:as => :string,
@@ -62,7 +62,7 @@
<%= f.submit t("helpers.submit.save"), :name => "draft", :class => "btn btn-primary" %>
- <%= f.submit t("helpers.submit.save_publish"), :name => "save_publish", :class => "btn btn-primary" %>
+ <%= f.submit t('helpers.submit.publish'), :name => "save_publish", :class => "btn btn-primary" %>
<%= link_to t("helpers.submit.cancel"), :back, :class => "btn cancel" %>
diff --git a/app/views/guidance_groups/admin_show.html.erb b/app/views/guidance_groups/admin_show.html.erb
index 670fb34..fe641ab 100644
--- a/app/views/guidance_groups/admin_show.html.erb
+++ b/app/views/guidance_groups/admin_show.html.erb
@@ -1,89 +1,92 @@
<%= stylesheet_link_tag "admin" %>
- <%= t("org_admin.guidance.guidance_group_label") %>
+ <%= t("org_admin.guidance.guidance_group_label") %>
-
-
|
| <%= t("org_admin.guidance_group.name_label") %> | -<%= raw @guidance_group.name %> | -
| - <% if @guidance_group.dmptemplates.count == 1 then %> - <%= t("org_admin.guidance.template") %> - <%else%> - <%= t("org_admin.guidance.templates") %> - <%end%> - | -<% i = 1 %> - <% if @guidance_group.dmptemplates.count == 0 then %> - <% list = Dmptemplate.funders_and_own_templates(current_user.organisation_id)%> - <% list.each do |tem|%> - <%= tem.title %> - <% if list.count > i then%> - , - <% i +=1 %> - <% end %> - <%end%> - <%else%> - <% @guidance_group.dmptemplates.each do |tem|%> - <%= tem.title %> - <% if @guidance_group.dmptemplates.count > i then%> - , - <% i +=1 %> - <% end %> - <%end%> - <%end%> - | -
| <%= t("org_admin.guidance_group.published") %> | -<%if @guidance_group.published.nil? || @guidance_group.published == false then%> - <%= t("helpers.no_label")%> - <%else%> - <%= t("helpers.yes_label")%> - <%end%> - | -
| <%= t("org_admin.guidance_group.subset") %> | -<%if @guidance_group.optional_subset.nil? || @guidance_group.optional_subset == false then%> - <%= t('helpers.no_label')%> - <%else%> - <%= t('helpers.yes_label')%> - <%end%> - | -
| <%= t("org_admin.guidance.created") %> | -<%= l @guidance_group.created_at.to_date, :formats => :short %> | -
| <%= t("org_admin.guidance.last_updated") %> | -<%= l @guidance_group.updated_at.to_date, :formats => :short %> | -
| <%= t("org_admin.guidance_group.name_label") %> | +<%= raw @guidance_group.name %> | +
| + <% if @guidance_group.dmptemplates.count == 1 then %> + <%= t("org_admin.guidance.template") %> + <% else %> + <%= t("org_admin.guidance.templates") %> + <% end %> + | ++ <% i = 1 %> + <% if @guidance_group.dmptemplates.count == 0 then %> + <% list = Dmptemplate.funders_and_own_templates(current_user.organisation_id) %> + <% list.each do |tem| %> + <%= tem.title %> + <% if list.count > i then %> + , + <% i +=1 %> + <% end %> + <% end %> + <% else %> + <% @guidance_group.dmptemplates.each do |tem| %> + <%= tem.title %> + <% if @guidance_group.dmptemplates.count > i then %> + , + <% i +=1 %> + <% end %> + <% end %> + <% end %> + | +
| <%= t('org_admin.templates.published_label') %> | ++ <% if @guidance_group.published.nil? || @guidance_group.published == false then %> + <%= t("helpers.no_label") %> + <% else %> + <%= t("helpers.yes_label") %> + <% end %> + | +
| <%= t("org_admin.guidance_group.subset") %> | ++ <% if @guidance_group.optional_subset.nil? || @guidance_group.optional_subset == false then %> + <%= t('helpers.no_label') %> + <% else %> + <%= t('helpers.yes_label') %> + <% end %> + | +
| <%= t("org_admin.guidance.created") %> | +<%= l @guidance_group.created_at.to_date, :formats => :short %> | +
| <%= t("org_admin.guidance.last_updated") %> | +<%= l @guidance_group.updated_at.to_date, :formats => :short %> | +