forked from diaspora/diaspora-project-site
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
made localization available to the users
* Setup the I18n system * Detect user language * Add locale switcher to footer
- Loading branch information
Showing
14 changed files
with
398 additions
and
70 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,6 @@ | ||
class I18nController < ApplicationController | ||
def switch_locale | ||
request.env["HTTP_REFERER"] ||= root_path | ||
redirect_to :back | ||
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
AVAILABLE_LOCALES = { | ||
en: "English", | ||
de: "Deutsch" | ||
} | ||
|
||
I18n.default_locale = :en | ||
I18n.available_locales = AVAILABLE_LOCALES.keys | ||
|
||
|
||
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) | ||
AVAILABLE_LOCALES.keys.each do |locale| | ||
I18n.fallbacks[locale] = [locale, I18n.default_locale] | ||
end | ||
|
||
RailsLocaleDetection.config do |config| | ||
config.locale_expiry = 3.months | ||
config.set_default_url_option = :explicity # valid values are true, false, :always, :never and :explicity | ||
config.detection_order = [:param, :user, :cookie, :request] | ||
config.automatically_detect = true | ||
config.locale_key = :locale | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module I18nHelper | ||
def locale_switcher_entries | ||
AVAILABLE_LOCALES.map { |key, name| | ||
locale_switcher_entry key, name | ||
}.join("\n").html_safe | ||
end | ||
|
||
def locale_switcher_entry key, name | ||
content_tag(:li, class: current_locale == key ? 'current' : nil) do | ||
link_to name, switch_locale_path(locale: key) | ||
end | ||
end | ||
end |
Oops, something went wrong.