diff --git a/app/admin/language.rb b/app/admin/language.rb new file mode 100644 index 0000000..777478c --- /dev/null +++ b/app/admin/language.rb @@ -0,0 +1,45 @@ +# [+Project:+] DMPonline +# [+Description:+] +# +# [+Created:+] 12/08/2016 +# [+Copyright:+] Digital Curation Centre + +ActiveAdmin.register Language do + permit_params :language_id, :name, :abbreviation, :default_language + + menu :priority => 10, :label => proc { I18n.t('admin.language') } + + index do + column I18n.t('admin.language_name'), :sortable => :name do |lang| + link_to lang.name, [:admin, lang] + end + column I18n.t('admin.language_abbreviation'), :sortable => :abbreviation do |lang| + link_to lang.abbreviation, [:admin, lang] + end + column I18n.t('admin.language_is_default'), :sortable => :default_language do |lang| + if lang[:default_language] + 'Yes' + else + 'No' + end + end + + actions + end + + show do + attributes_table do + row :name + row :abbreviation + row :default_language + row :description + end + end + + controller do + def permitted_params + params.permit! + end + end + +end \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cf4b5da..ecca66a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -25,8 +25,9 @@ elsif user_signed_in? and !current_user[:language_id].nil? I18n.locale = Language.find_by_id(current_user[:language_id]).abbreviation # 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 + elsif user_signed_in? and current_user.organisation.present? and !current_user.organisation[:language_id].nil? + I18n.locale = Language.find_by_id(current_user.organisation[:language_id]).abbreviation + # use user's organization language, keep in mine the "OTHER ORG" edge case which should use default language else # just use the default language, line can be commented out, included just for clarity I18n.locale = I18n.default_locale diff --git a/config/initializers/locale.rb b/config/initializers/locale.rb index a2e0323..261f930 100644 --- a/config/initializers/locale.rb +++ b/config/initializers/locale.rb @@ -9,7 +9,12 @@ # in config/initializers/locale.rb # set default locale to something other than :en - config.i18n.default_locale = Language.where(default_language: true).first.abbreviation + # initializers are run before migrations, languages table might not be present + if ActiveRecord::Base.connection.tables.include?('languages') + config.i18n.default_locale = Language.where(default_language: true).first.abbreviation + else + config.i18n.default_locale = 'en-UK' # if this is not set then admin area is not working, which is required to change the default_language + end # set fallback locale config.i18n.fallbacks = true diff --git a/config/locales/en-UK.yml b/config/locales/en-UK.yml index ad8b06f..c3c1b1b 100644 --- a/config/locales/en-UK.yml +++ b/config/locales/en-UK.yml @@ -42,6 +42,12 @@ screencast_error_text: "Your browser does not support the video tag." admin: + language: "Language" + language_name: "Language name" + language_abbreviation: "Language abbreviation" + language_is_default: "Is default language" + yes: "Yes" + no: "No" org_title: "Organisation name" org: "Organisation" orgs: "Organisations"