Merged Rails 2.2 branch. Redmine now requires Rails 2.2.2.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2493 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2009-02-21 11:04:50 +00:00
parent 9a986ac0a5
commit fe28193e4e
237 changed files with 27994 additions and 32194 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ module Redmine
class DataAlreadyLoaded < Exception; end
module Loader
include GLoc
include Redmine::I18n
class << self
# Returns true if no data is already loaded in the database
+2 -1
View File
@@ -22,10 +22,11 @@ require 'rfpdf/chinese'
module Redmine
module Export
module PDF
include ActionView::Helpers::TextHelper
include ActionView::Helpers::NumberHelper
class IFPDF < FPDF
include GLoc
include Redmine::I18n
attr_accessor :footer_date
def initialize(lang)
+2 -2
View File
@@ -20,7 +20,7 @@ module Redmine
# Simple class to compute the start and end dates of a calendar
class Calendar
include GLoc
include Redmine::I18n
attr_reader :startdt, :enddt
def initialize(date, lang = current_language, period = :month)
@@ -28,7 +28,7 @@ module Redmine
@events = []
@ending_events_by_days = {}
@starting_events_by_days = {}
set_language lang
set_language_if_valid lang
case period
when :month
@startdt = Date.civil(date.year, date.month, 1)
+1 -1
View File
@@ -70,7 +70,7 @@ module Redmine
# Base class for hook listeners.
class Listener
include Singleton
include GLoc
include Redmine::I18n
# Registers the listener
def self.inherited(child)
+79
View File
@@ -0,0 +1,79 @@
module Redmine
module I18n
def self.included(base)
base.extend Redmine::I18n
end
def l(*args)
case args.size
when 1
::I18n.t(*args)
when 2
if args.last.is_a?(Hash)
::I18n.t(*args)
elsif args.last.is_a?(String)
::I18n.t(args.first, :value => args.last)
else
::I18n.t(args.first, :count => args.last)
end
else
raise "Translation string with multiple values: #{args.first}"
end
end
def l_or_humanize(s, options={})
k = "#{options[:prefix]}#{s}".to_sym
::I18n.t(k, :default => s.to_s.humanize)
end
def l_hours(hours)
hours = hours.to_f
l((hours < 2.0 ? :label_f_hour : :label_f_hour_plural), :value => ("%.2f" % hours.to_f))
end
def ll(lang, str, value=nil)
::I18n.t(str.to_s, :value => value, :locale => lang.to_s.gsub(%r{(.+)\-(.+)$}) { "#{$1}-#{$2.upcase}" })
end
def format_date(date)
return nil unless date
Setting.date_format.blank? ? ::I18n.l(date.to_date) : date.strftime(Setting.date_format)
end
def format_time(time, include_date = true)
return nil unless time
time = time.to_time if time.is_a?(String)
zone = User.current.time_zone
local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time)
Setting.time_format.blank? ? ::I18n.l(local, :format => (include_date ? :default : :time)) :
((include_date ? "#{format_date(time)} " : "") + "#{local.strftime(Setting.time_format)}")
end
def day_name(day)
::I18n.t('date.day_names')[day % 7]
end
def month_name(month)
::I18n.t('date.month_names')[month]
end
def valid_languages
@@valid_languages ||= Dir.glob(File.join(RAILS_ROOT, 'config', 'locales', '*.yml')).collect {|f| File.basename(f).split('.').first}.collect(&:to_sym)
end
def find_language(lang)
@@languages_lookup = valid_languages.inject({}) {|k, v| k[v.to_s.downcase] = v; k }
@@languages_lookup[lang.to_s.downcase]
end
def set_language_if_valid(lang)
if l = find_language(lang)
::I18n.locale = l
end
end
def current_language
::I18n.locale
end
end
end
+4 -7
View File
@@ -15,8 +15,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'gloc'
module Redmine
module MenuManager
module MenuController
@@ -101,7 +99,7 @@ module Redmine
item.url
end
caption = item.caption(project)
caption = l(caption) if caption.is_a?(Symbol)
caption = l_or_humanize(caption, :prefix => 'label_') if caption.is_a?(Symbol)
if block_given?
yield item, caption, url, (current_menu_item == item.name)
else
@@ -178,7 +176,7 @@ module Redmine
end
class MenuItem
include GLoc
include Redmine::I18n
attr_reader :name, :url, :param, :condition
def initialize(name, url, options)
@@ -188,7 +186,7 @@ module Redmine
@url = url
@condition = options[:if]
@param = options[:param] || :id
@caption = options[:caption]
@caption = options[:caption] || @name
@html_options = options[:html] || {}
# Adds a unique class to each menu item based on its name
@html_options[:class] = [@html_options[:class], @name.to_s.dasherize].compact.join(' ')
@@ -200,8 +198,7 @@ module Redmine
c = @name.to_s.humanize if c.blank?
c
else
# check if localized string exists on first render (after GLoc strings are loaded)
@caption_key ||= (@caption || (l_has_string?("label_#{@name}".to_sym) ? "label_#{@name}".to_sym : @name.to_s.humanize))
@caption
end
end
+3
View File
@@ -67,6 +67,9 @@ module Redmine #:nodoc:
p.instance_eval(&block)
# Set a default name if it was not provided during registration
p.name(id.to_s.humanize) if p.name.nil?
# Adds plugin locales if any
# YAML translation files should be found under <plugin>/config/locales/
::I18n.load_path += Dir.glob(File.join(RAILS_ROOT, 'vendor', 'plugins', id.to_s, 'config', 'locales', '*.yml'))
registered_plugins[id] = p
end
+1 -1
View File
@@ -18,7 +18,7 @@
require 'action_view/helpers/form_helper'
class TabularFormBuilder < ActionView::Helpers::FormBuilder
include GLoc
include Redmine::I18n
def initialize(object_name, object, template, options, proc)
set_language_if_valid options.delete(:lang)
+24
View File
@@ -0,0 +1,24 @@
desc 'Generates a configuration file for cookie store sessions.'
file 'config/initializers/session_store.rb' do
path = File.join(RAILS_ROOT, 'config', 'initializers', 'session_store.rb')
secret = ActiveSupport::SecureRandom.hex(40)
File.open(path, 'w') do |f|
f.write <<"EOF"
# This file was generated by 'rake config/initializers/session_store.rb',
# and should not be made visible to public.
# If you have a load-balancing Redmine cluster, you will need to use the
# same version of this file on each machine. And be sure to restart your
# server when you modify this file.
# Your secret key for verifying cookie session data integrity. If you
# change this key, all old sessions will become invalid! Make sure the
# secret is at least 30 characters and all random, no regular words or
# you'll be exposed to dictionary attacks.
ActionController::Base.session = {
:session_key => '_redmine_session',
:secret => '#{secret}'
}
EOF
end
end
+3 -3
View File
@@ -2,14 +2,14 @@ desc 'Load Redmine default configuration data'
namespace :redmine do
task :load_default_data => :environment do
include GLoc
include Redmine::I18n
set_language_if_valid('en')
puts
while true
print "Select language: "
print GLoc.valid_languages.sort {|x,y| x.to_s <=> y.to_s }.join(", ")
print " [#{GLoc.current_language}] "
print valid_languages.collect(&:to_s).sort.join(", ")
print " [#{current_language}] "
lang = STDIN.gets.chomp!
break if lang.empty?
break if set_language_if_valid(lang)