@@ -90,10 +90,18 module Redmine | |||
|
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 | |
|
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 | |
|
95 | 102 | 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 } | |
|
103 | languages_options :cache => false | |
|
104 | end | |
|
97 | 105 |
end |
|
98 | 106 | end |
|
99 | 107 |
@@ -198,6 +198,11 class Redmine::I18nTest < ActiveSupport::TestCase | |||
|
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 |
General Comments 0
You need to be logged in to leave comments.
Login now