Module: Redmine::I18n
- Included in:
- ApplicationController, ApplicationHelper, Mailer, QueryColumn, DefaultData::Loader, Export::PDF::IFPDF, Helpers::Calendar, Hook::Listener, MenuManager::MenuItem, TabularFormBuilder
- Defined in:
- lib/redmine/i18n.rb
Class Method Summary
Instance Method Summary
- - (Object) current_language
- - (Object) day_name(day)
- - (Object) find_language(lang)
- - (Object) format_date(date)
- - (Object) format_time(time, include_date = true)
- - (Object) l(*args)
- - (Object) l_hours(hours)
- - (Object) l_or_humanize(s, options = {})
- - (Object) ll(lang, str, value = nil)
- - (Object) month_name(month)
- - (Object) set_language_if_valid(lang)
- - (Object) valid_languages
Class Method Details
+ (Object) included(base)
3 4 5 |
# File 'lib/redmine/i18n.rb', line 3 def self.included(base) base.extend Redmine::I18n end |
Instance Method Details
- (Object) current_language
75 76 77 |
# File 'lib/redmine/i18n.rb', line 75 def current_language ::I18n.locale end |
- (Object) day_name(day)
52 53 54 |
# File 'lib/redmine/i18n.rb', line 52 def day_name(day) ::I18n.t('date.day_names')[day % 7] end |
- (Object) find_language(lang)
64 65 66 67 |
# File 'lib/redmine/i18n.rb', line 64 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 |
- (Object) format_date(date)
38 39 40 41 |
# File 'lib/redmine/i18n.rb', line 38 def format_date(date) return nil unless date Setting.date_format.blank? ? ::I18n.l(date.to_date) : date.strftime(Setting.date_format) end |
- (Object) format_time(time, include_date = true)
43 44 45 46 47 48 49 50 |
# File 'lib/redmine/i18n.rb', line 43 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 |
- (Object) l(*args)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/redmine/i18n.rb', line 7 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 |
- (Object) l_hours(hours)
29 30 31 32 |
# File 'lib/redmine/i18n.rb', line 29 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 |
- (Object) l_or_humanize(s, options = {})
24 25 26 27 |
# File 'lib/redmine/i18n.rb', line 24 def l_or_humanize(s, ={}) k = "#{options[:prefix]}#{s}".to_sym ::I18n.t(k, :default => s.to_s.humanize) end |
- (Object) ll(lang, str, value = nil)
34 35 36 |
# File 'lib/redmine/i18n.rb', line 34 def ll(lang, str, value=nil) ::I18n.t(str.to_s, :value => value, :locale => lang.to_s.gsub(%r{(.+)\-(.+)$}) { "#{$1}-#{$2.upcase}" }) end |
- (Object) month_name(month)
56 57 58 |
# File 'lib/redmine/i18n.rb', line 56 def month_name(month) ::I18n.t('date.month_names')[month] end |
- (Object) set_language_if_valid(lang)
69 70 71 72 73 |
# File 'lib/redmine/i18n.rb', line 69 def set_language_if_valid(lang) if l = find_language(lang) ::I18n.locale = l end end |
- (Object) valid_languages
60 61 62 |
# File 'lib/redmine/i18n.rb', line 60 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 |