Defect #12861 ยป revert-r10844.diff
app/helpers/application_helper.rb | ||
---|---|---|
925 | 925 |
end |
926 | 926 | |
927 | 927 |
def lang_options_for_select(blank=true) |
928 |
(blank ? [["(auto)", ""]] : []) + languages_options |
|
928 |
(blank ? [["(auto)", ""]] : []) + |
|
929 |
valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last } |
|
929 | 930 |
end |
930 | 931 | |
931 | 932 |
def label_tag_for(name, option_tags = nil, options = {}) |
lib/redmine/i18n.rb | ||
---|---|---|
87 | 87 |
::I18n.available_locales |
88 | 88 |
end |
89 | 89 | |
90 |
# Returns an array of languages names and code sorted by names, example: |
|
91 |
# [["Deutsch", "de"], ["English", "en"] ...] |
|
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 |
|
98 |
end |
|
99 | ||
100 | 90 |
def find_language(lang) |
101 | 91 |
@@languages_lookup = valid_languages.inject({}) {|k, v| k[v.to_s.downcase] = v; k } |
102 | 92 |
@@languages_lookup[lang.to_s.downcase] |
test/unit/lib/redmine/i18n_test.rb | ||
---|---|---|
194 | 194 |
assert valid_languages.first.is_a?(Symbol) |
195 | 195 |
end |
196 | 196 | |
197 |
def test_languages_options |
|
198 |
options = languages_options |
|
199 | ||
200 |
assert options.is_a?(Array) |
|
201 |
assert_equal valid_languages.size, options.size |
|
202 |
assert_nil options.detect {|option| !option.is_a?(Array)} |
|
203 |
assert_nil options.detect {|option| option.size != 2} |
|
204 |
assert_nil options.detect {|option| !option.first.is_a?(String) || !option.last.is_a?(String)} |
|
205 |
assert_include ["English", "en"], options |
|
206 |
end |
|
207 | ||
208 | 197 |
def test_locales_validness |
209 | 198 |
lang_files_count = Dir["#{Rails.root}/config/locales/*.yml"].size |
210 | 199 |
assert_equal lang_files_count, valid_languages.size |