Skip to content

Commit

Permalink
change locale and default locale
Browse files Browse the repository at this point in the history
  • Loading branch information
marcometz committed Mar 5, 2014
1 parent 06893d6 commit 15b47e5
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ group :development do
gem 'brakeman'
gem 'hirb'
gem "powder"
gem 'debugger'
end

group :test do
Expand Down
16 changes: 9 additions & 7 deletions app/controllers/goldencobra/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ def show
end

def switch_language
I18n.locale = params[:locale] || session[:locale]
session[:locale] = I18n.locale
if params[:locale].present?
I18n.locale = params[:locale]
session[:locale] = I18n.locale.to_s
else
I18n.locale = session[:locale]
end
if params[:redirect_to].present?
redirect_to params[:redirect_to]
else
Expand Down Expand Up @@ -109,7 +113,7 @@ def verify_token

def get_article
if is_startpage?
I18n.locale = :de
I18n.locale = I18n.default_locale
@article = Goldencobra::Article.active.startpage.first
else
begin
Expand Down Expand Up @@ -293,11 +297,9 @@ def geocode_ip_address
if session[:user_location].blank?
#Geokit::Geocoders::MultiGeocoder.geocode("194.39.218.11") schlägt fehl (Completed 500 Internal Server Error) daher...
begin
@ip_result = Geokit::Geocoders::MultiGeocoder.geocode(request.remote_ip)
session[:user_location] = @ip_result
@ip_result = Geokit::Geocoders::MultiGeocoder.geocode(request.remote_ip)
session[:user_location] = @ip_result
rescue Exception => e
logger.error("***********")
logger.error(e)
@ip_result = nil
end
if @ip_result.present? && @ip_result.city.present?
Expand Down
9 changes: 3 additions & 6 deletions lib/goldencobra/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@ class Engine < ::Rails::Engine
isolate_namespace Goldencobra
initializer "goldencobra.load_app_instance_data" do |app|
#app.class.configure do
# #Pull in all the migrations from goldencobra to the application
# config.paths['db/migrate'] += Goldencobra::Engine.paths['db/migrate'].existent
#call some action
#end
end

initializer("goldencobra.locales") do |app|
#tracking_logger = Logger.new(app.root.join('log', "my_engine_log.log"), 10, 30*1024*1024)
Goldencobra::Engine.config.i18n.load_path += Dir[root.join('config', 'locales', '*.{rb,yml}').to_s]
Goldencobra::Engine.config.i18n.default_locale = :de
Goldencobra::Engine.config.i18n.fallbacks = [:en]
#tracking_logger.debug "MyEngine::Engine specific locale settings are set. Def locale == :ru\n\n"
#Goldencobra::Engine.config.i18n.default_locale = :de
#Goldencobra::Engine.config.i18n.fallbacks = [:en]
end

config.to_prepare do
Expand Down
5 changes: 4 additions & 1 deletion test/dummy/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@



<%= I18n.locale %>
Default Locale: <%= I18n.default_locale %>
Locale: <%= I18n.locale %>
Session: <%= session[:locale] %>
<br>
<%= link_to "Deutsch", switch_language_path("de") %>
<%= link_to "Englisch", switch_language_path("en") %>
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class Application < Rails::Application
I18n.reload!
self.reload_routes!
end
Rails.logger.warn("==== Locale #{I18n.locale}")
end

end
end

6 changes: 4 additions & 2 deletions test/dummy/config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: utf-8

Dummy::Application.configure do
# Settings specified here will take precedence over those in config/application.rb

Expand Down Expand Up @@ -35,7 +37,7 @@
# Expands the lines which load the assets
config.assets.debug = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.i18n.default_locale = :de
config.i18n.locale = :de
config.i18n.default_locale = :en
config.i18n.locale = :en
config.time_zone = 'Berlin'
end
2 changes: 2 additions & 0 deletions test/dummy/config/initializers/active_admin.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: utf-8

ActiveAdmin.setup do |config|
#if ActiveAdmin::VERSION == "0.3.4" && Rails.version == "3.2.0.rc2"
# class ActiveSupport::FileUpdateChecker
Expand Down

0 comments on commit 15b47e5

Please sign in to comment.