comparison lib/redmine/i18n.rb @ 909:cbb26bc654de redmine-1.3

Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author Chris Cannam
date Fri, 24 Feb 2012 19:09:32 +0000
parents 051f544170fe
children 433d4f72a19b
comparison
equal deleted inserted replaced
908:c6c2cbd0afee 909:cbb26bc654de
1 module Redmine 1 module Redmine
2 module I18n 2 module I18n
3 def self.included(base) 3 def self.included(base)
4 base.extend Redmine::I18n 4 base.extend Redmine::I18n
5 end 5 end
6 6
7 def l(*args) 7 def l(*args)
8 case args.size 8 case args.size
9 when 1 9 when 1
10 ::I18n.t(*args) 10 ::I18n.t(*args)
11 when 2 11 when 2
23 23
24 def l_or_humanize(s, options={}) 24 def l_or_humanize(s, options={})
25 k = "#{options[:prefix]}#{s}".to_sym 25 k = "#{options[:prefix]}#{s}".to_sym
26 ::I18n.t(k, :default => s.to_s.humanize) 26 ::I18n.t(k, :default => s.to_s.humanize)
27 end 27 end
28 28
29 def l_hours(hours) 29 def l_hours(hours)
30 hours = hours.to_f 30 hours = hours.to_f
31 l((hours < 2.0 ? :label_f_hour : :label_f_hour_plural), :value => ("%.2f" % hours.to_f)) 31 l((hours < 2.0 ? :label_f_hour : :label_f_hour_plural), :value => ("%.2f" % hours.to_f))
32 end 32 end
33 33
34 def ll(lang, str, value=nil) 34 def ll(lang, str, value=nil)
35 ::I18n.t(str.to_s, :value => value, :locale => lang.to_s.gsub(%r{(.+)\-(.+)$}) { "#{$1}-#{$2.upcase}" }) 35 ::I18n.t(str.to_s, :value => value, :locale => lang.to_s.gsub(%r{(.+)\-(.+)$}) { "#{$1}-#{$2.upcase}" })
36 end 36 end
37 37
38 def format_date(date) 38 def format_date(date)
39 return nil unless date 39 return nil unless date
40 Setting.date_format.blank? ? ::I18n.l(date.to_date) : date.strftime(Setting.date_format) 40 Setting.date_format.blank? ? ::I18n.l(date.to_date) : date.strftime(Setting.date_format)
41 end 41 end
42 42
43 def format_time(time, include_date = true) 43 def format_time(time, include_date = true)
44 return nil unless time 44 return nil unless time
45 time = time.to_time if time.is_a?(String) 45 time = time.to_time if time.is_a?(String)
46 zone = User.current.time_zone 46 zone = User.current.time_zone
47 local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time) 47 local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time)
50 end 50 end
51 51
52 def day_name(day) 52 def day_name(day)
53 ::I18n.t('date.day_names')[day % 7] 53 ::I18n.t('date.day_names')[day % 7]
54 end 54 end
55 55
56 def month_name(month) 56 def month_name(month)
57 ::I18n.t('date.month_names')[month] 57 ::I18n.t('date.month_names')[month]
58 end 58 end
59 59
60 def valid_languages 60 def valid_languages
61 @@valid_languages ||= Dir.glob(File.join(RAILS_ROOT, 'config', 'locales', '*.yml')).collect {|f| File.basename(f).split('.').first}.collect(&:to_sym) 61 @@valid_languages ||= Dir.glob(File.join(Rails.root, 'config', 'locales', '*.yml')).collect {|f| File.basename(f).split('.').first}.collect(&:to_sym)
62 end 62 end
63 63
64 def find_language(lang) 64 def find_language(lang)
65 @@languages_lookup = valid_languages.inject({}) {|k, v| k[v.to_s.downcase] = v; k } 65 @@languages_lookup = valid_languages.inject({}) {|k, v| k[v.to_s.downcase] = v; k }
66 @@languages_lookup[lang.to_s.downcase] 66 @@languages_lookup[lang.to_s.downcase]
67 end 67 end
68 68
69 def set_language_if_valid(lang) 69 def set_language_if_valid(lang)
70 if l = find_language(lang) 70 if l = find_language(lang)
71 ::I18n.locale = l 71 ::I18n.locale = l
72 end 72 end
73 end 73 end
74 74
75 def current_language 75 def current_language
76 ::I18n.locale 76 ::I18n.locale
77 end 77 end
78 end 78 end
79 end 79 end