Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select language according to http accept-language parameter #73

Merged
merged 2 commits into from
Jun 9, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,6 @@ gem 'koala'

# Additional features for text searching with mongoid
gem 'mongoid_fulltext'

# Internationalization according to http accept-language
gem 'http_accept_language'
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ GEM
tilt (>= 1.3.3)
hike (1.2.2)
hirefireapp (0.1.2)
http_accept_language (1.0.2)
i18n (0.6.1)
jammit (0.6.6)
cssmin (>= 1.0.3)
Expand Down Expand Up @@ -317,6 +318,7 @@ DEPENDENCIES
haml-rails
haml_coffee_assets
hirefireapp
http_accept_language
jammit
jquery-rails (= 2.1.4)
koala
Expand Down
12 changes: 11 additions & 1 deletion app/controllers/web/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
class Web::ApplicationController < ApplicationController

before_filter :set_locale

# will be reset every deploy
caches_action :index

def index
@options = {}
end

AVAILABLE_LANGUAGES = I18n.available_locales.map do |l| l.to_s end
def set_locale
unless request.user_preferred_languages.empty?
I18n.locale = request.preferred_language_from(AVAILABLE_LANGUAGES)
else
I18n.locale = I18n.default_locale
end
end

private
def set_election
@only_published_candidacies = true
Expand Down
2 changes: 1 addition & 1 deletion app/views/web/application/_templates.mustache.haml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
{{/user.name}}

{{^user.name}}
<a href="#" class="connect">Connexion</a>
<a href="#" class="connect">#{ t 'account.sign_in' }</a>
{{/user.name}}

%script#users-new-template{type: "text/html"}
Expand Down
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Joinplato::Application.configure do
# Settings specified here will take precedence over those in config/application.rb

# Setting up locale
config.i18n.default_locale = :en

# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
Expand Down
3 changes: 3 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true

# Setting up default locale
config.i18n.default_locale = :en

# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify

Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ en:
password: Password
sign_up: Sign up
already_on_voxe_sign_in: Already on Voxe? Sign in.
sign_in: Sign in
sign_in: Log in
edit_my_profile: Edit my profile
6 changes: 3 additions & 3 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ fr:
navigation:
about: Projet
how: Sources
press: On parle de nous
press: Presse
apps: Apps
API: Développeurs
API: API
hackathon: Hackathon
method: Méthode
donate: Soutenir
Expand Down Expand Up @@ -35,5 +35,5 @@ fr:
password: Mot de passe
sign_up: S'inscrire
already_on_voxe_sign_in: Déjà sur Voxe? Se connecter.
sign_in: Se connecter
sign_in: Connexion
edit_my_profile: Editer mon profile