diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-10-20 21:10:32 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-10-20 21:10:32 +0000 |
commit | 778625de9a00d2c0bc2f660a7e9bf7b9ac8f8bfd (patch) | |
tree | b8cb24629517f5a68c6a37db18448b123750d97c | |
parent | 5bbcc0698a184224d3f121fea75085982e9ee0d9 (diff) | |
download | redmine-778625de9a00d2c0bc2f660a7e9bf7b9ac8f8bfd.tar.gz redmine-778625de9a00d2c0bc2f660a7e9bf7b9ac8f8bfd.zip |
Merged r13450 (#18110).
git-svn-id: http://svn.redmine.org/redmine/branches/2.6-stable@13462 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | lib/redmine/i18n.rb | 18 | ||||
-rw-r--r-- | test/unit/lib/redmine/i18n_test.rb | 5 |
2 files changed, 18 insertions, 5 deletions
diff --git a/lib/redmine/i18n.rb b/lib/redmine/i18n.rb index 11be1b613..3e783170f 100644 --- a/lib/redmine/i18n.rb +++ b/lib/redmine/i18n.rb @@ -90,11 +90,19 @@ module Redmine # Returns an array of languages names and code sorted by names, example: # [["Deutsch", "de"], ["English", "en"] ...] # - # The result is cached to prevent from loading all translations files. - def languages_options - ActionController::Base.cache_store.fetch "i18n/languages_options" do - valid_languages.map {|lang| [ll(lang.to_s, :general_lang_name), lang.to_s]}.sort {|x,y| x.first <=> y.first } - end + # The result is cached to prevent from loading all translations files + # unless :cache => false option is given + def languages_options(options={}) + if options[:cache] == false + valid_languages. + select {|locale| ::I18n.exists?(:general_lang_name, locale)}. + map {|lang| [ll(lang.to_s, :general_lang_name), lang.to_s]}. + sort {|x,y| x.first <=> y.first } + else + ActionController::Base.cache_store.fetch "i18n/languages_options" do + languages_options :cache => false + end + end end def find_language(lang) diff --git a/test/unit/lib/redmine/i18n_test.rb b/test/unit/lib/redmine/i18n_test.rb index fc1fdf3d1..6d3561486 100644 --- a/test/unit/lib/redmine/i18n_test.rb +++ b/test/unit/lib/redmine/i18n_test.rb @@ -198,6 +198,11 @@ class Redmine::I18nTest < ActiveSupport::TestCase assert_include [ja, "ja"], options end + def test_languages_options_should_ignore_locales_without_general_lang_name_key + stubs(:valid_languages).returns([:en, :foo]) + assert_equal [["English", "en"]], languages_options(:cache => false) + end + def test_locales_validness lang_files_count = Dir["#{Rails.root}/config/locales/*.yml"].size assert_equal lang_files_count, valid_languages.size |