diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2176cbfb..4dc368a5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 50f9e7ca..3ed56ede 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7283d93e..6bbad7a5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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, diff --git a/app/views/shared/settings/_account.html.erb b/app/views/shared/settings/_account.html.erb index 4a8eb00b..8d09d1c8 100644 --- a/app/views/shared/settings/_account.html.erb +++ b/app/views/shared/settings/_account.html.erb @@ -34,6 +34,9 @@
<%= f.label t("settings.account.provider"), class: "form-label" %> <%= f.text_field :provider, class: "form-control", readonly: "" %> +
+ <%= 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" %>
diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 7e559297..71ca0b15 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -19,7 +19,7 @@
- + diff --git a/config/application.rb b/config/application.rb index c3de455b..daaf72c2 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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? diff --git a/config/initializers/languages.rb b/config/initializers/languages.rb new file mode 100644 index 00000000..4ba2d340 --- /dev/null +++ b/config/initializers/languages.rb @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 20ed59b1..6df77ff9 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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! @@ -101,7 +110,7 @@ en: or: or with: Sign in with %{provider} rename_recording: - + rename_room: name_placeholder: Enter a new room name... name_update_success: Room name successfully changed! @@ -144,6 +153,7 @@ en: settings: account: fullname: Fullname + language: Language provider: Provider image: Image image_url: Profile Image URL diff --git a/config/locales/es.yml b/config/locales/es.yml index c3e3529a..00dc850e 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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: diff --git a/db/migrate/20181113174230_add_language_to_user.rb b/db/migrate/20181113174230_add_language_to_user.rb new file mode 100644 index 00000000..4b01a766 --- /dev/null +++ b/db/migrate/20181113174230_add_language_to_user.rb @@ -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 . + +class AddLanguageToUser < ActiveRecord::Migration[5.0] + def change + add_column :users, :language, :string, default: 'default' + end +end diff --git a/db/schema.rb b/db/schema.rb index c90470ee..434d6c02 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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