Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #433 from drusepth/start-i18n
Internationalize strings
- Loading branch information
Showing
24 changed files
with
548 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.