Merge pull request #24 from zach-chai/localization

Localization
This commit is contained in:
Zachary Chai 2016-11-03 17:37:48 -04:00 committed by GitHub
commit c9aaf2346a
16 changed files with 110 additions and 67 deletions

View File

@ -60,3 +60,5 @@ gem 'bootstrap-social-rails', '~> 4.12'
gem 'font-awesome-rails' gem 'font-awesome-rails'
gem 'jquery-ui-rails' gem 'jquery-ui-rails'
gem 'jquery-datatables-rails', '~> 3.4.0' gem 'jquery-datatables-rails', '~> 3.4.0'
gem 'http_accept_language'

View File

@ -70,6 +70,7 @@ GEM
globalid (0.3.7) globalid (0.3.7)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
hashie (3.4.4) hashie (3.4.4)
http_accept_language (2.1.0)
i18n (0.7.0) i18n (0.7.0)
jbuilder (2.6.0) jbuilder (2.6.0)
activesupport (>= 3.0.0, < 5.1) activesupport (>= 3.0.0, < 5.1)
@ -212,6 +213,7 @@ DEPENDENCIES
coffee-rails (~> 4.2) coffee-rails (~> 4.2)
dotenv-rails dotenv-rails
font-awesome-rails font-awesome-rails
http_accept_language
jbuilder (~> 2.5) jbuilder (~> 2.5)
jquery-datatables-rails (~> 3.4.0) jquery-datatables-rails (~> 3.4.0)
jquery-rails jquery-rails

View File

@ -84,14 +84,14 @@
info: false, info: false,
ordering: false, ordering: false,
language: { language: {
emptyTable: "Past recordings are shown here." emptyTable: " "
}, },
columns: [ columns: [
{ title: "Date Recorded", data: "start_time" }, { data: "start_time" },
{ title: "Presentation", data: "previews"}, { data: "previews"},
{ title: "Duration", data: "duration" }, { data: "duration" },
{ title: "Views", data: "playbacks" }, { data: "playbacks" },
{ title: "Actions", data: "id" } { data: "id" }
], ],
columnDefs: [ columnDefs: [
{ {
@ -186,7 +186,8 @@
data.recordings[i].duration = totalMinutes; data.recordings[i].duration = totalMinutes;
data.recordings[i].start_time = new Date(data.recordings[i].start_time) data.recordings[i].start_time = new Date(data.recordings[i].start_time)
.toLocaleString([], {month: 'long', day: 'numeric', year: 'numeric', hour12: 'true', hour: '2-digit', minute: '2-digit'}); .toLocaleString($('html').attr('lang'),
{month: 'long', day: 'numeric', year: 'numeric', hour12: 'true', hour: '2-digit', minute: '2-digit'});
} }
table.clear(); table.clear();
table.rows.add(data.recordings); table.rows.add(data.recordings);

View File

@ -3,6 +3,11 @@ require 'digest/sha1'
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
protect_from_forgery with: :exception protect_from_forgery with: :exception
before_action :set_locale
def set_locale
I18n.locale = http_accept_language.language_region_compatible_from(I18n.available_locales)
end
def current_user def current_user
@current_user ||= User.find_by(id: session[:user_id]) @current_user ||= User.find_by(id: session[:user_id])

View File

@ -19,14 +19,6 @@ class User < ApplicationRecord
auth_hash['info']['nickname'] auth_hash['info']['nickname']
end end
def ownership_name
if username.end_with? 's'
"#{username}'"
else
"#{username}'s"
end
end
def room_url def room_url
"/rooms/#{username}" "/rooms/#{username}"
end end

View File

@ -15,7 +15,7 @@ unless @response.blank?
end end
json.playbacks do json.playbacks do
json.array!(recording[:playbacks]) do |playback| json.array!(recording[:playbacks]) do |playback|
json.type playback[:type] json.type t(playback[:type]) # translates the playback type
json.url playback[:url] json.url playback[:url]
json.previews do json.previews do
json.array!(playback[:previews]) do |preview| json.array!(playback[:previews]) do |preview|

View File

@ -1,9 +1,9 @@
<% content_for :title do %> <% content_for :title do %>
<div class="title"> <div class="title">
Hi Everyone <%= t('hi_all') %>
</div> </div>
<small> <small>
The session will be taking place using the following URL <%= t('session_url_explanation') %>
</small> </small>
<% end %> <% end %>
@ -11,7 +11,7 @@
<% content_for :footer do %> <% content_for :footer do %>
<div class="panel-footer"> <div class="panel-footer">
<div class="text-center"> <div class="text-center">
<a href="#" class="generate-link">Click refresh</a> to generate a new meeting URL <%= t('refresh_html') %>
</div> </div>
</div> </div>
<% end %> <% end %>
@ -20,7 +20,7 @@
<div class="page-wrapper meetings"> <div class="page-wrapper meetings">
<div class='container-fluid'> <div class='container-fluid'>
<%= render 'shared/title', title: 'Start A New Session' %> <%= render 'shared/title', title: t('start_new_session') %>
<%= render layout: 'shared/center_panel' do %> <%= render layout: 'shared/center_panel' do %>
<div class="center-block col-sm-8"> <div class="center-block col-sm-8">

View File

@ -1,17 +1,17 @@
<% if current_user %> <% if current_user %>
<% page_title = "Welcome, #{current_user.name.split(' ').first}" %> <% page_title = t('greet_user', name: current_user.name) %>
<% else %> <% else %>
<% page_title = "Welcome to #{@user.ownership_name} Meeting Space" %> <% page_title= t('greet_guest', name: @user.username) %>
<% end %> <% end %>
<% content_for :title do %> <% content_for :title do %>
<div class="title"> <div class="title">
<% if current_user == @user %> <% if current_user == @user %>
Start a new session <%= t('start_new_session') %>
<% elsif current_user && current_user != @user %> <% elsif current_user && current_user != @user %>
<%= "Join #{@user.ownership_name} session" %> <%= t('join_session_user', name: @user.username) %>
<% else %> <% else %>
Join the current session <%= t('join_session_guest') %>
<% end %> <% end %>
</div> </div>
<% end %> <% end %>
@ -35,8 +35,16 @@
</div> </div>
<div class="table-wrapper"> <div class="table-wrapper">
<h3>Past Recordings</h3> <h3><%= t('past_recordings') %></h3>
<table id="recordings" class="table" width="100%"></table> <table id="recordings" class="table" width="100%">
<thead>
<th><%= t('date_recorded') %></th>
<th><%= t('presentation') %></th>
<th><%= t('duration') %></th>
<th><%= t('views') %></th>
<th><%= t('actions') %></th>
</thead>
</table>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,9 +1,9 @@
<% content_for :title do %> <% content_for :title do %>
<div class="title"> <div class="title">
Looks like you're the first one here... <%= t('wait_for_mod_msg') %>
</div> </div>
<small> <small>
You will automatically join when the meeting starts <%= t('wait_for_mod_explanation') %>
</small> </small>
<% end %> <% end %>

View File

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="<%= I18n.locale %>">
<head> <head>
<title>Greenlight</title> <title>Greenlight</title>
<%= csrf_meta_tags %> <%= csrf_meta_tags %>
@ -17,22 +17,22 @@
<!-- Header --> <!-- Header -->
<div class='header'> <div class='header'>
<span class="logo-wrapper pull-left"> <span class="logo-wrapper pull-left">
<%= link_to image_tag("bbb-logo.png", :alt => "BigBlueButton Demo", :class => "logo"), root_path %> <%= link_to image_tag("bbb-logo.png", :alt => "BigBlueButton", :class => "logo"), root_path %>
</span> </span>
<span class="signup pull-right"> <span class="signup pull-right">
<% if current_user %> <% if current_user %>
<%= current_user.name %> | <%= current_user.name %> |
<% if current_user.username %> <% if current_user.username %>
<%= link_to 'my room', current_user.room_url %> | <%= link_to t('my_room'), current_user.room_url %> |
<% else %> <% else %>
<%= link_to 'my room', edit_user_path(current_user) %> | <%= link_to t('my_room'), edit_user_path(current_user) %> |
<% end %> <% end %>
<%= link_to 'logout', user_logout_url %> <%= link_to t('logout'), user_logout_url %>
<% elsif @user %> <% elsif @user %>
Are you <%= @user.username %> ? | <%= t('are_you', name: @user.username) %> |
<%= link_to 'login', "/auth/#{@user.provider}" %> <%= link_to t('login'), "/auth/#{@user.provider}" %>
<% else %> <% else %>
Signup for customized sessions <%= t('oauth_signup') %>
<%= link_to('/auth/twitter', :class => "btn icon btn-lg btn-social-icon btn-twitter") do %> <%= link_to('/auth/twitter', :class => "btn icon btn-lg btn-social-icon btn-twitter") do %>
<span class="fa fa-twitter"></span> <span class="fa fa-twitter"></span>
<% end %> <% end %>
@ -48,7 +48,7 @@
<!-- Footer --> <!-- Footer -->
<div class='footer text-center'> <div class='footer text-center'>
Powered by BigBlueButton <%= t('powered_bigbluebutton') %>
</div> </div>
<!-- End of Footer --> <!-- End of Footer -->
</body> </body>

View File

@ -3,20 +3,20 @@
<% @current_user = user %> <% @current_user = user %>
<%= text_field :current_user, :name, class: 'form-control meeting-user-name', type: 'hidden' %> <%= text_field :current_user, :name, class: 'form-control meeting-user-name', type: 'hidden' %>
<% else %> <% else %>
<%= text_field :nil, :nil, class: 'form-control meeting-user-name', placeholder: 'Enter your name' %> <%= text_field :nil, :nil, class: 'form-control meeting-user-name', placeholder: t('enter_name') %>
<% end %> <% end %>
<% if admin? %> <% if admin? %>
<button type="button" class="btn btn-primary center-block meeting-join"> <button type="button" class="btn btn-primary center-block meeting-join">
Start <%= t('start') %>
</button> </button>
<% elsif current_user %> <% elsif current_user %>
<button type="button" class="btn btn-primary center-block meeting-join"> <button type="button" class="btn btn-primary center-block meeting-join">
Join <%= t('join') %>
</button> </button>
<% else %> <% else %>
<span class="input-group-btn"> <span class="input-group-btn">
<button type="button" class="btn btn-primary meeting-join"> <button type="button" class="btn btn-primary meeting-join">
Join <%= t('join') %>
</button> </button>
</span> </span>
<% end %> <% end %>

View File

@ -8,6 +8,6 @@
</span> </span>
</div> </div>
<small> <small>
<em>Copy this URL to invite others to the meeting</em> <em><%= t('url_copy_explanation') %></em>
</small> </small>
</div> </div>

View File

@ -12,6 +12,13 @@ module Greenlight
# Application configuration should go into files in config/initializers # Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded. # -- all .rb files in that directory are automatically loaded.
# i18n
# ensure each language has a regional fallback
config.i18n.available_locales = %w(en en-US)
config.i18n.default_locale = 'en-US'
config.i18n.fallbacks = {'en' => 'en-US'}
# BigBlueButton
config.bigbluebutton_endpoint = ENV['BIGBLUEBUTTON_ENDPOINT'] config.bigbluebutton_endpoint = ENV['BIGBLUEBUTTON_ENDPOINT']
config.bigbluebutton_secret = ENV['BIGBLUEBUTTON_SECRET'] config.bigbluebutton_secret = ENV['BIGBLUEBUTTON_SECRET']
end end

View File

@ -1,5 +1,5 @@
Rails.application.config.middleware.use OmniAuth::Builder do Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, ENV['TWITTER_ID'], ENV['TWITTER_SECRET'] provider :twitter, ENV['TWITTER_ID'], ENV['TWITTER_SECRET']
provider :google_oauth2, ENV['GOOGLE_OAUTH2_ID'], ENV['GOOGLE_OAUTH2_SECRET'], provider :google_oauth2, ENV['GOOGLE_OAUTH2_ID'], ENV['GOOGLE_OAUTH2_SECRET'],
scope: 'profile', access_type: 'online', name: 'google' scope: ['profile'], access_type: 'online', name: 'google'
end end

49
config/locales/en-us.yml Normal file
View File

@ -0,0 +1,49 @@
# Files in the config/locales directory are used for internationalization
# and are automatically loaded by Rails. If you want to use locales other
# than English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t 'hello'
#
# In views, this is aliased to just `t`:
#
# <%= t('hello') %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# To learn more, please read the Rails Internationalization guide
# available at http://guides.rubyonrails.org/i18n.html.
en-US:
actions: Actions
are_you: Are you %{name} ?
date_recorded: Date Recorded
duration: Duration
enter_name: Enter your name
greet_user: Welcome, %{name}
greet_guest: Welcome to %{name} Meeting Space
hi_all: Hi Everyone
join: Join
join_session_guest: Join the current session
join_session_user: Join %{name} session
login: login
logout: logout
my_room: my room
oauth_signup: Signup for customized sessions
past_recordings: Past Recordings
powered_bigbluebutton: Powered by BigBlueButton
presentation: Presentation
refresh_html: <a href="#" class="generate-link">Click refresh</a> to generate a new meeting URL
session_url_explanation: The session will be taking place using the following URL
start: Start
start_new_session: Start a new session
url_copy_explanation: Copy this URL to invite others to the meeting
video: Video
views: Views
wait_for_mod_msg: Looks like you're the first one here...
wait_for_mod_explanation: You will automatically join when the meeting starts

View File

@ -1,23 +0,0 @@
# Files in the config/locales directory are used for internationalization
# and are automatically loaded by Rails. If you want to use locales other
# than English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t 'hello'
#
# In views, this is aliased to just `t`:
#
# <%= t('hello') %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# To learn more, please read the Rails Internationalization guide
# available at http://guides.rubyonrails.org/i18n.html.
en:
hello: "Hello world"