Commit fb97141d authored by jplang's avatar jplang

Cache languages names to avoid loading all translations files.

git-svn-id: https://svn.redmine.org/redmine/trunk@10844 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent fd609b35
......@@ -962,8 +962,7 @@ module ApplicationHelper
end
def lang_options_for_select(blank=true)
(blank ? [["(auto)", ""]] : []) +
valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
(blank ? [["(auto)", ""]] : []) + languages_options
end
def label_tag_for(name, option_tags = nil, options = {})
......
......@@ -70,6 +70,16 @@ module Redmine
::I18n.available_locales
end
# 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
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]
......
......@@ -194,6 +194,17 @@ class Redmine::I18nTest < ActiveSupport::TestCase
assert valid_languages.first.is_a?(Symbol)
end
def test_languages_options
options = languages_options
assert options.is_a?(Array)
assert_equal valid_languages.size, options.size
assert_nil options.detect {|option| !option.is_a?(Array)}
assert_nil options.detect {|option| option.size != 2}
assert_nil options.detect {|option| !option.first.is_a?(String) || !option.last.is_a?(String)}
assert_include ["English", "en"], options
end
def test_locales_validness
lang_files_count = Dir["#{Rails.root}/config/locales/*.yml"].size
assert_equal lang_files_count, valid_languages.size
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment