Project

General

Profile

« Previous | Next » 

Revision 13450

Ignore locales without :general_lang_name key (#18110).

View differences:

trunk/lib/redmine/i18n.rb
90 90
    # Returns an array of languages names and code sorted by names, example:
91 91
    # [["Deutsch", "de"], ["English", "en"] ...]
92 92
    #
93
    # The result is cached to prevent from loading all translations files.
94
    def languages_options
95
      ActionController::Base.cache_store.fetch "i18n/languages_options" do
96
        valid_languages.map {|lang| [ll(lang.to_s, :general_lang_name), lang.to_s]}.sort {|x,y| x.first <=> y.first }
97
      end      
93
    # The result is cached to prevent from loading all translations files
94
    # unless :cache => false option is given
95
    def languages_options(options={})
96
      if options[:cache] == false
97
        valid_languages.
98
          select {|locale| ::I18n.exists?(:general_lang_name, locale)}.
99
          map {|lang| [ll(lang.to_s, :general_lang_name), lang.to_s]}.
100
          sort {|x,y| x.first <=> y.first }
101
      else
102
        ActionController::Base.cache_store.fetch "i18n/languages_options" do
103
          languages_options :cache => false
104
        end
105
      end
98 106
    end
99 107

  
100 108
    def find_language(lang)
trunk/test/unit/lib/redmine/i18n_test.rb
198 198
    assert_include [ja, "ja"], options
199 199
  end
200 200

  
201
  def test_languages_options_should_ignore_locales_without_general_lang_name_key
202
    stubs(:valid_languages).returns([:en, :foo])
203
    assert_equal [["English", "en"]], languages_options(:cache => false)
204
  end
205

  
201 206
  def test_locales_validness
202 207
    lang_files_count = Dir["#{Rails.root}/config/locales/*.yml"].size
203 208
    assert_equal lang_files_count, valid_languages.size

Also available in: Unified diff