Skip to content

Commit

Permalink
Merge pull request #433 from drusepth/start-i18n
Browse files Browse the repository at this point in the history
Internationalize strings
  • Loading branch information
drusepth committed Apr 29, 2015
2 parents 8b4bef1 + bc41bc0 commit 7a22c77
Show file tree
Hide file tree
Showing 24 changed files with 548 additions and 304 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -7,8 +7,9 @@
# Ignore bundler config
/.bundle

# Ingore Yardoc temp files
# Ingore Yardoc temp files and generated documentation
/.yardoc
/doc

# Ignore the default SQLite database.
/db/*.sqlite3
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -8,6 +8,7 @@ gem 'paperclip', '~> 4.2.0'
gem 'rmagick', '2.13.4'
gem 'aws-sdk', '~> 1.50'
gem 'bcrypt', '~> 3.1.10', platforms: [:ruby, :mingw, :x64_mingw]
gem 'rails-i18n', '~> 4.0.0'

group :production do
gem 'less-rails'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Expand Up @@ -125,6 +125,9 @@ GEM
bundler (>= 1.3.0, < 2.0)
railties (= 4.1.0)
sprockets-rails (~> 2.0)
rails-i18n (4.0.4)
i18n (~> 0.6)
railties (~> 4.0)
railties (4.1.0)
actionpack (= 4.1.0)
activesupport (= 4.1.0)
Expand Down Expand Up @@ -222,6 +225,7 @@ DEPENDENCIES
paperclip (~> 4.2.0)
pg
rails (= 4.1.0)
rails-i18n (~> 4.0.0)
rmagick (= 2.13.4)
rubocop
sass-rails (~> 4.0.3)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
@@ -1,5 +1,6 @@
# Superclass for all model controllers
class ApplicationController < ActionController::Base
include Localized
protect_from_forgery

helper :html
Expand Down
50 changes: 50 additions & 0 deletions app/controllers/concerns/localized.rb
@@ -0,0 +1,50 @@
require 'active_support/concern'

# Sets the locale for every request, from the first available value among
# the following:
# 1. a URL parameter called "locale", ex. +?locale=en+
# 2. the +HTTP_ACCEPT_LANGUAGE+ header property
# 3. the default locale in +I18n.default_locale+
module Localized
extend ActiveSupport::Concern

included do
before_action :set_locale
end

# Sets +I18n.locale+ from the first available value among the following:
# 1. a URL parameter called "locale", ex. +?locale=en+
# 2. the +HTTP_ACCEPT_LANGUAGE+ header property
# 3. the default locale in +I18n.default_locale+
def set_locale
I18n.locale = requested_locale || I18n.default_locale
end

# The locale requested by the user. Returns the first available value:
# 1. a URL paramter called "locale"
# 2. the +HTTP_ACCEPT_LANGUAGE+ header property
def requested_locale
validate_locale locale_from_url_params ||
locale_from_accept_language_header
end

# Returns the given locale if localizations for it are available.
# Returns nil otherwise.
def validate_locale(locale)
return if locale.blank?
locale if locale.to_sym.in?(I18n.available_locales)
end

# The locale in the URL paramters
def locale_from_url_params
params[:locale]
end

# The two-character locale in the +HTTP_ACCEPT_LANGUAGE+ header field
def locale_from_accept_language_header
return if request.blank?
return if request.env['HTTP_ACCEPT_LANGUAGE'].blank?

request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
end
end
20 changes: 10 additions & 10 deletions app/views/layouts/_login_box.html.erb
Expand Up @@ -6,22 +6,22 @@
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="/account">Logged in as <%= User.find(session[:user]).name %></a></li>
<li><%= link_to t('.logged_in_as', username: User.find(session[:user]).name), account_path %></a></li>
<li class="divider"></li>
<li><a href="/my/content">My Content</a></li>
<li><a href="/account">Account Settings</a></li>
<li><%= link_to t('.my_content'), dashboard_path %></li>
<li><%= link_to t('.account_settings'), account_path %></li>
<li class="divider"></li>
<li><a href="/about/privacy">Privacy Policy</a></li>
<li><%= link_to t('.privacy_policy'), privacy_info_path %></li>
<li class="divider"></li>
<li><a href="https://docs.google.com/forms/d/198QvP092YZn9adeCkLjU_Jw4BHZaSMYjU8p0F8V7csw/viewform" target="_blank">Report a problem</a></li>
<li><a href="https://docs.google.com/forms/d/11O6mHMIFFbNiUfdj6eqStXnARPcj3tWnYOQ-90QktDk/viewform" target="_blank">Give feedback</a></li>
<li><a href="https://docs.google.com/forms/d/1ncA82di103_e3KjG8PCHO9g9RQY0_89I6mSQf2L0S4g/viewform" target="_blank">Request a feature</a></li>
<li><%= link_to t('.report_a_problem'), 'https://docs.google.com/forms/d/198QvP092YZn9adeCkLjU_Jw4BHZaSMYjU8p0F8V7csw/viewform', target: '_blank' %></li>
<li><%= link_to t('.give_feedback'), 'https://docs.google.com/forms/d/11O6mHMIFFbNiUfdj6eqStXnARPcj3tWnYOQ-90QktDk/viewform', target: '_blank' %></li>
<li><%= link_to t('.request_a_feature'), 'https://docs.google.com/forms/d/1ncA82di103_e3KjG8PCHO9g9RQY0_89I6mSQf2L0S4g/viewform', target: '_blank' %></li>
<li class="divider"></li>
<li><a href="/logout">Log out</a></li>
<li><%= link_to t('.log_out'), logout_path %></li>
</ul>
</li>
<% else %>
<li><a href="/login">Login</a></li>
<li><a href="/register">Register</a></li>
<li><%= link_to t('.login'), login_path %></li>
<li><%= link_to t('.register'), signup_path %></a></li>
<% end %>
</ul>
22 changes: 13 additions & 9 deletions app/views/layouts/_navbar.html.erb
@@ -1,25 +1,29 @@
<nav class="navbar navbar-fixed-top" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="sr-only"><%= t '.toggle_navigation' %></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Indent</a>
<%= link_to t('.brand'), homepage_path, class: "navbar-brand" %>
</div>

<div class="collapse navbar-collapse" id="navbar-container">
<ul class="nav navbar-nav">
<% if session[:user] %>
<li><a href="/"><span class="glyphicon glyphicon-home"></span></a></li>
<li>
<%= link_to homepage_path do %>
<span class="glyphicon glyphicon-home"></span>
<% end %>
</li>
<% end %>
<li><a href="/plan/characters">Characters</a></li>
<li class="active"><a href="/plan/equipment">Equipment</a></li>
<li><a href="/plan/languages">Languages</a></li>
<li><a href="/plan/locations">Locations</a></li>
<li><a href="/plan/magic">Magic</a></li>
<li><a href="/plan/universes">Universes</a></li>
<li><%= link_to Character.model_name.human.pluralize, character_list_path %></li>
<li><%= link_to Equipment.model_name.human.pluralize, equipment_list_path %></li>
<li><%= link_to Language.model_name.human.pluralize, language_list_path %></li>
<li><%= link_to Location.model_name.human.pluralize, location_list_path %></li>
<li><%= link_to Magic.model_name.human.pluralize, magic_list_path %></li>
<li><%= link_to Universe.model_name.human.pluralize, universe_list_path %></li>
</ul>

<div class="navbar-right">
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_noscript_notice.html.erb
@@ -1,7 +1,7 @@
<noscript>
<div class="navbar" style="padding: 12px; margin-top: -20px; background: #ff2211; border-bottom: 1px solid #ffbbaa; text-align: center; text: black;">
<div class="container">
Please enable Javascript for the site to function correctly. We promise not to do anything bad!
<%= t '.paragraph_1' %>
</div>
</div>
</noscript>
25 changes: 12 additions & 13 deletions app/views/layouts/_sidebar.html.erb
Expand Up @@ -20,39 +20,38 @@
<% if session[:anon_user] and session[:user] and User.find(session[:user]).content_count > 0 && !current_page?(account_path) %>
<div class="card">
<div class="card-heading">Anonymous accounts</div>
<div class="card-heading"><%= t '.anonymous_accounts' %></div>
<div class="card-body">
You are currently using an <a href="/about/anon-login">anonymous account</a>. In order to save the brilliant things you have created with it, please <a href="/account">click here</a> to give yourself a username and password.
<%= t '.anon_account_explanation',
anon_account: link_to(t('.anon_account'), anon_info_path),
click_here: link_to(t('.click_here')) %>
</div>
<div class="card-comments"></div>
</div>
<% end %>
<% unless session[:user] %>
<div class="card">
<h1 class="card-heading">Get started instantly</h1>
<h1 class="card-heading"><%= t '.getstarted_header' %></h1>
<div class="card-body">
Nobody likes creating accounts just to try things out. You can get started making things immediately and create your account later if you want.
<%= t '.getstarted_description' %>
</div>
<div class="card-comments">
<div class="comments-collapse-toggle">
<p>
<a href="/anon-login">Get started</a> or
<%= link_to t('.getstarted_link'), anonymous_login_path %>
<%= t '.or' %>
<a data-toggle="collapse" data-target="#c1-comments" href="#">
Learn more <i class="icon-angle-down"></i>
<%= t '.learnmore_link' %> <i class="icon-angle-down"></i>
</a>
</p>
</div>
<div id="c1-comments" class="comments collapse">
<p>
If you jump right in to creating things, an account will be created for you. As you flesh out characters and worlds, your ideas will be safe and sound under this account, which does not ever expire unless you delete it yourself.
</p>
<p>
At any time, you can change the account's login information, so if you make some good progress you can just create an account and <em>tada!</em> all of your ideas are private to your new account, always there for you.
</p>
<p><%= t '.learnmore_p1_html' %></p>
<p><%= t '.learnmore_p2_html' %></p>
<p>
<a data-toggle="collapse" data-target="#c1-comments" href="#">
Collapse card <i class="icon-angle-up"></i>
<%= t '.collapse_card' %> <i class="icon-angle-up"></i>
</a>
</p>
</div>
Expand Down
10 changes: 5 additions & 5 deletions app/views/layouts/application.html.erb
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="<%= I18n.locale %>">
<head>
<title>Indent</title>
<%= stylesheet_link_tag "application", :media => "all" %>
Expand Down Expand Up @@ -28,10 +28,10 @@
<div class="row">
<div class="col-md-12">
<p>
Indent &middot;
<a href="/about/attribution">Image Attribution</a> &middot;
<a href="/about/privacy">Privacy Policy</a> &middot;
<a href="https://github.com/drusepth/Indent">Source Code</a>
<%= t '.brand' %> &middot;
<%= link_to t('.image_attribution'), attribution_info_path %> &middot;
<%= link_to t('.privacy_policy'), privacy_info_path %> &middot;
<%= link_to t('.source_code'), 'https://github.com/drusepth/Indent' %>
</p>
</div>
</div>
Expand Down
15 changes: 15 additions & 0 deletions app/views/main/_artist_card.html.erb
@@ -0,0 +1,15 @@
<div class="col-xs-3">
<div class="card">
<h1 class="card-heading"><%= artist_name %></h1>
<%= link_to image_source do %>
<%= image_tag image, style: "width: 100%" %>
<% end %>
<div class="card-comments">
<% if artist_gallery %>
<%= link_to artist_gallery do %>
<%= t '.more_by_this_artist' %>
<% end %>
<% end %>
</div>
</div>
</div>
29 changes: 5 additions & 24 deletions app/views/main/_dashboard_intro.html.erb
@@ -1,37 +1,18 @@
<div class="row">
<div class="col-md-4">
<div class="card">
<h1 class="card-heading">This is is your dashboard</h1>
<div class="card-body">
<p>
As you plan your stories, you can always return back here to get a view of everything
you've created at a glance. To get back here from anywhere, simply click the
<strong>Indent</strong> logo up top, or the <span class="glyphicon glyphicon-home"></span> icon next to it.
</p>
<p>
Good luck and have fun!
</p>
</div>
<h1 class="card-heading"><%= t '.card_1_heading' %></h1>
<div class="card-body"><%= t '.card_1_body_html' %></div>
<div class="card-comments"></div>
</div>
</div>

<div class="col-md-4">
<div class="card">
<h1 class="card-heading">Ready to get started?</h1>
<div class="card-body">
<p>
Welcome to Indent. Before you get started, it's recommended that you
<%= link_to "create a universe", :universe_create %>.
</p>
<p>
This universe will contain
everything you create about your world, and is a handy way to keep multiple worlds
cleanly separated during the planning process.
</p>
</div>
<h1 class="card-heading"><%= t '.card_2_heading' %></h1>
<div class="card-body"><%= t('.card_2_body_html', create_universe_link: link_to(t('.create_universe_link_title'), :universe_create)) %></div>
<div class="card-comments">
<%= link_to "Create a universe!", :universe_create %>
<%= link_to t('.create_universe_button'), :universe_create %>
</div>
</div>
</div>
Expand Down
12 changes: 12 additions & 0 deletions app/views/main/_model_card.html.erb
@@ -0,0 +1,12 @@
<div class="col-sm-3">
<div class="card">
<h1 class="card-heading"><%= model_name %></h1>
<%= image_tag image %>
<div class="card-body">
<p><%= description %></p>
</div>
<div class="card-comments">
<%= link_to t('.plan_your_own'), plan_path, class: "btn" %>
</div>
</div>
</div>
21 changes: 5 additions & 16 deletions app/views/main/anoninfo.html.erb
@@ -1,21 +1,10 @@
<div class="card">
<h3 class="card-heading simple">What are "Anonymous" accounts?</h3>
<h3 class="card-heading simple"><%= t '.heading' %></h3>
<div class="card-body">
<p>
Nobody likes having to create an account before being able to check out something cool.
</p>

<p>
So you don't need an account. If you're just browsing or deciding whether or not it's worth creating an account, you can simply log in with the big, blue <a href="/be-anonymous">Be Anonymous</a> button.
</p>

<p>
Clicking the button will generate a random account and automatically log you in, letting you jump right in to planning your stories. Everything acts exactly as it would if you were logged in to a "real" account, except with one caveat:
</p>

<p>
<strong>If you log out or close your browser without <a href="/account">setting a username and password for yourself</a>, your account will be deleted.</strong> To keep all of your content, all you have to do is visit <a href="/account">this page</a> and type in the login information you want to use &ndash; it's that easy. All of your content will be saved and you can log in to your account with that username in the future.
</p>
<p><%= t '.paragraph_1_html' %></p>
<p><%= t '.paragraph_2_html' %></p>
<p><%= t '.paragraph_3_html' %></p>
<p><%= t '.paragraph_4_html' %></p>
</div>
<div class="card-comments"></div>
</div>
Expand Down

0 comments on commit 7a22c77

Please sign in to comment.