end
def set_locale
+ if @user
+ if !@user.languages.empty?
+ request.user_preferred_languages = @user.languages
+ elsif !request.user_preferred_languages.empty?
+ @user.languages = request.user_preferred_languages
+ @user.save
+ end
+ end
+
I18n.locale = request.compatible_language_from(I18n.available_locales)
end
class BrowseController < ApplicationController
layout 'site'
- before_filter :set_locale
before_filter :authorize_web
+ before_filter :set_locale
before_filter { |c| c.check_database_readable(true) }
def start
require 'xml/libxml'
session :off, :except => [:list, :list_user, :list_bbox]
- before_filter :set_locale, :only => [:list, :list_user, :list_bbox]
before_filter :authorize_web, :only => [:list, :list_user, :list_bbox]
+ before_filter :set_locale, :only => [:list, :list_user, :list_bbox]
before_filter :authorize, :only => [:create, :update, :delete, :upload, :include, :close]
before_filter :require_public_data, :only => [:create, :update, :delete, :upload, :include, :close]
before_filter :check_api_writable, :only => [:create, :update, :delete, :upload, :include]
class ChangesetTagController < ApplicationController
layout 'site'
- before_filter :set_locale
-
def search
@tags = ChangesetTag.find(:all, :limit => 11, :conditions => ["match(v) against (?)", params[:query][:query].to_s] )
end
-
end
class DiaryEntryController < ApplicationController
layout 'site', :except => :rss
- before_filter :set_locale
before_filter :authorize_web
+ before_filter :set_locale
before_filter :require_user, :only => [:new, :edit]
before_filter :check_database_readable
before_filter :check_database_writable, :only => [:new, :edit]
render :action => 'edit'
end
else
- @diary_entry = DiaryEntry.new(:language => @user.language)
+ @diary_entry = DiaryEntry.new(:language_code => @user.preferred_language)
render :action => 'edit'
end
end
class ExportController < ApplicationController
+ before_filter :authorize_web
before_filter :set_locale
def start
class MessageController < ApplicationController
layout 'site'
- before_filter :set_locale
before_filter :authorize_web
+ before_filter :set_locale
before_filter :require_user
before_filter :check_database_readable
before_filter :check_database_writable, :only => [:new, :reply, :mark]
class SiteController < ApplicationController
- before_filter :set_locale
before_filter :authorize_web
+ before_filter :set_locale
before_filter :require_user, :only => [:edit]
def export
class TraceController < ApplicationController
layout 'site'
- before_filter :set_locale
before_filter :authorize_web
+ before_filter :set_locale
before_filter :require_user, :only => [:mine, :create, :edit, :delete, :make_public]
before_filter :authorize, :only => [:api_details, :api_data, :api_create]
before_filter :check_database_readable, :except => [:api_details, :api_data, :api_create]
layout 'site'
before_filter :authorize, :only => [:api_details, :api_gpx_files]
- before_filter :set_locale, :except => [:api_details, :api_gpx_files]
before_filter :authorize_web, :except => [:api_details, :api_gpx_files]
+ before_filter :set_locale, :except => [:api_details, :api_gpx_files]
before_filter :require_user, :only => [:set_home, :account, :go_public, :make_friend, :remove_friend, :upload_image, :delete_image]
before_filter :check_database_readable, :except => [:api_details, :api_gpx_files]
before_filter :check_database_writable, :only => [:login, :new, :set_home, :account, :go_public, :make_friend, :remove_friend, :upload_image, :delete_image]
@user.data_public = true
@user.description = "" if @user.description.nil?
@user.creation_ip = request.remote_ip
- @user.locale = Language.find_by_code(I18n.locale.to_s)
- @user.locale = Language.find_by_code("en") if @user.locale.nil?
+ @user.languages = request.user_preferred_languages
if @user.save
flash[:notice] = I18n.t('user.new.flash create success message')
class Language < ActiveRecord::Base
set_primary_key :code
- has_many :users, :foreign_key => 'locale'
has_many :diary_entries, :foreign_key => 'language'
def name
class User < ActiveRecord::Base
require 'xml/libxml'
- belongs_to :language, :foreign_key => 'locale'
-
has_many :traces
has_many :diary_entries, :order => 'created_at DESC'
has_many :messages, :foreign_key => :to_user_id, :order => 'sent_on DESC'
return el1
end
+ def languages
+ attribute_present?(:languages) ? read_attribute(:languages).split(",") : []
+ end
+
+ def languages=(languages)
+ write_attribute(:languages, languages.join(","))
+ end
+
+ def preferred_language
+ languages.find { |l| Language.find(:first, :conditions => { :code => l }) }
+ end
+
def nearby(radius = 50, num = 10)
if self.home_lon and self.home_lat
gc = OSM::GreatCircle.new(self.home_lat, self.home_lon)
--- /dev/null
+require 'lib/migrate'
+
+class ChangeUserLocale < ActiveRecord::Migration
+ def self.up
+ remove_foreign_key :users, [:locale], :languages, [:code]
+
+ rename_column :users, :locale, :languages
+ end
+
+ def self.down
+ rename_column :users, :languages, :locale
+
+ add_foreign_key :users, [:locale], :languages, [:code]
+ end
+end
[]
end
+ # Sets the user languages preference, overiding the browser
+ #
+ def user_preferred_languages=(languages)
+ @user_preferred_languages = languages.join(",")
+ end
+
# Finds the locale specifically requested by the browser.
#
# Example: