Start adding some i18n.
This commit is contained in:
parent
988dbbad42
commit
4d3857c135
5 changed files with 30 additions and 3 deletions
|
|
@ -1,3 +1,15 @@
|
|||
class ApplicationController < ActionController::Base
|
||||
protect_from_forgery
|
||||
|
||||
# Setup the locale based on the domain name used to access the website
|
||||
before_filter :set_locale
|
||||
|
||||
private
|
||||
|
||||
# This sets the locale based on hostname. (see config/initializers/locales.rb)
|
||||
# Can be overridden with locale parameter, i.e. http://localhost:3000/?locale=de
|
||||
def set_locale
|
||||
this_domain_ext = request.host.split('.').last
|
||||
I18n.locale = params[:locale] || DEFAULT_LANGUAGE_BY_DOMAIN[this_domain_ext] || 'en'
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
<div class="row">
|
||||
<div class="twelvecol">
|
||||
<h1>Birthdays</h1>
|
||||
<h2>for the next 7 days</h2>
|
||||
<h1><%= t("birthdays.birthdays") %></h1>
|
||||
<h2><%= t("birthdays.for_next_days") %></h2>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
9
config/initializers/locales.rb
Normal file
9
config/initializers/locales.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
# Build map of domain extensions and their corresponding language.
|
||||
# array contains: domain extension, locale
|
||||
#
|
||||
DEFAULT_LANGUAGE_BY_DOMAIN = {
|
||||
"com" => "en",
|
||||
"net" => "en",
|
||||
"de" => "de"
|
||||
}
|
||||
4
config/locales/de.yml
Normal file
4
config/locales/de.yml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
de:
|
||||
birthdays:
|
||||
birthdays: "Geburtstage"
|
||||
for_next_days: "für die nächsten 7 Tage"
|
||||
|
|
@ -2,4 +2,6 @@
|
|||
# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
||||
|
||||
en:
|
||||
hello: "Hello world"
|
||||
birthdays:
|
||||
birthdays: "Birthdays"
|
||||
for_next_days: "for the next 7 days"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue