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

@ -37,6 +37,10 @@ module Greenlight
config.i18n.available_locales = %w(en pt-br es ar fr de el)
config.i18n.default_locale = "en"
config.i18n.available_locales.each do |locale|
config.i18n.fallbacks[locale] = [locale, :en]
end
# Check if a loadbalancer is configured.
config.loadbalanced_configuration = ENV["LOADBALANCER_ENDPOINT"].present? && ENV["LOADBALANCER_SECRET"].present?

View File

@ -0,0 +1,13 @@
# frozen_string_literal: true
# Load available languages.
locales = "#{Rails.root}/config/locales/*"
configured_languages = []
Dir.glob(locales) do |loc|
configured_languages.push(loc.split('/').last.split('.').first)
end
Rails.configuration.languages = configured_languages

View File

@ -77,6 +77,15 @@ en:
video: Watch our tutorial on using Greenlight
upgrade: Show me how to upgrade to 2.0!
version: We've released a new version of Greenlight, but your database isn't compatible.
language_options:
default: Default (browser language)
ar: Arabic
de: German
el: Greek
en: English
es: Spanish
fr: French
pt-br: Portuguese (Brazil)
ldap_error: Unable to connect to the LDAP server. Please check your LDAP configuration in the env file and ensure your server is running.
login: Sign in
max_concurrent: The maximum number of concurrent sessions allowed has been reached!
@ -144,6 +153,7 @@ en:
settings:
account:
fullname: Fullname
language: Language
provider: Provider
image: Image
image_url: Profile Image URL

View File

@ -26,7 +26,7 @@ es:
enter_your_name: Introduce tu nombre
errors:
internal:
message: Oh no! PArece que algo falló de tu lado.
message: Oh no! Parece que algo falló de tu lado.
help: "El error ha sido registrado, vamos a revisarlo."
migration_error:
contact_admin: "Sí tu no eres administrador, contacta a uno."
@ -69,6 +69,15 @@ es:
video: Ve nuestro tutorial de como utilizar Greenlight
upgrade: Muestrame como actualizar a versión 2.0
version: Hemos publicado una nueva version de Greenlight pero tu base de datos no es compatible.
language_options:
default: Por omisión (idioma del navegador)
ar: Árabe
de: Alemán
el: Griego
en: Inglés
es: Español
fr: Francés
pt-br: Portugués (Brasil)
ldap_error: No se puede conectar al servidor LDAP. Compruebe la configuración de LDAP en el archivo "env" y asegúrate de que tu servidor está ejecutándose.
login: Ingresar
modal:

View File

@ -0,0 +1,23 @@
# frozen_string_literal: true
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
class AddLanguageToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :language, :string, default: 'default'
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180920193451) do
ActiveRecord::Schema.define(version: 20181113174230) do
create_table "rooms", force: :cascade do |t|
t.integer "user_id"
@ -40,9 +40,10 @@ ActiveRecord::Schema.define(version: 20180920193451) do
t.string "image"
t.string "password_digest"
t.boolean "accepted_terms", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "email_verified", default: false
t.string "language", default: "default"
t.index ["password_digest"], name: "index_users_on_password_digest", unique: true
t.index ["room_id"], name: "index_users_on_room_id"
end