Fixed #323 Allow users to select a language in settings (GRN-17) (#324)

* <Added ui for language setting and migration>

* <Option to choose languages added>

* <Fixed code style>

* <Added Rspec tests>

* <sync db>

* <Sync db>

* <Generalized language settings>

* <Fixed flash message>

* Fixed las issue with i18n fallback

* <Modified fallback config>

* <Fixed code style>
This commit is contained in:
John Ma
2018-12-06 16:00:22 -05:00
committed by Jesus Federico
parent 895af7494e
commit b3f37cd3b3
11 changed files with 89 additions and 8 deletions

View File

@ -39,7 +39,15 @@ class ApplicationController < ActionController::Base
# Sets the appropriate locale.
def set_locale
I18n.locale = http_accept_language.language_region_compatible_from(I18n.available_locales)
update_locale(current_user)
end
def update_locale(user)
I18n.locale = if user && user.language != 'default'
user.language
else
http_accept_language.language_region_compatible_from(I18n.available_locales)
end
end
def meeting_name_limit

View File

@ -93,6 +93,7 @@ class UsersController < ApplicationController
@user.update_attributes(email_verified: false)
redirect_to edit_user_path(@user), notice: I18n.t("info_update_success")
elsif @user.update_attributes(user_params)
update_locale(@user)
redirect_to edit_user_path(@user), notice: I18n.t("info_update_success")
else
render :edit, params: { settings: params[:settings] }
@ -171,6 +172,6 @@ class UsersController < ApplicationController
def user_params
params.require(:user).permit(:name, :email, :image, :password, :password_confirmation,
:new_password, :provider, :accepted_terms)
:new_password, :provider, :accepted_terms, :language)
end
end

View File

@ -46,6 +46,15 @@ module ApplicationHelper
Rails.configuration.bigbluebutton_endpoint_default == Rails.configuration.bigbluebutton_endpoint
end
# Returns language selection options
def language_options
language_opts = [['<<<< ' + t("language_options.default") + ' >>>>', "default"]]
Rails.configuration.languages.each do |loc|
language_opts.push([t("language_options." + loc), loc])
end
language_opts.sort
end
# Parses markdown for rendering.
def markdown(text)
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,

View File

@ -34,6 +34,9 @@
<br>
<%= f.label t("settings.account.provider"), class: "form-label" %>
<%= f.text_field :provider, class: "form-control", readonly: "" %>
<br>
<%= f.label t("settings.account.language"), class: "form-label" %>
<%= f.select :language, language_options, {}, { class: "form-control custom-select" } %>
<%= f.label t("settings.account.image"), class: "form-label mt-5" %>
<div class="row">

View File

@ -19,7 +19,7 @@
<div class="row">
<div class="col-lg-3 mb-4">
<div class="list-group list-group-transparent mb-0">
<button id="account" class="list-group-item list-group-item-action setting-btn <%= "active" if !params[:setting] || params[:setting] == "account"%>">
<span class="icon mr-3"><i class="fas fa-user"></i></span><%= t("settings.account.title") %>
</button>