@@ -90,11 +90,19 module Redmine | |||||
90 | # Returns an array of languages names and code sorted by names, example: |
|
90 | # Returns an array of languages names and code sorted by names, example: | |
91 | # [["Deutsch", "de"], ["English", "en"] ...] |
|
91 | # [["Deutsch", "de"], ["English", "en"] ...] | |
92 | # |
|
92 | # | |
93 |
# The result is cached to prevent from loading all translations files |
|
93 | # The result is cached to prevent from loading all translations files | |
94 | def languages_options |
|
94 | # unless :cache => false option is given | |
95 | ActionController::Base.cache_store.fetch "i18n/languages_options" do |
|
95 | def languages_options(options={}) | |
96 | valid_languages.map {|lang| [ll(lang.to_s, :general_lang_name), lang.to_s]}.sort {|x,y| x.first <=> y.first } |
|
96 | if options[:cache] == false | |
97 | end |
|
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 | end |
|
106 | end | |
99 |
|
107 | |||
100 | def find_language(lang) |
|
108 | def find_language(lang) |
@@ -198,6 +198,11 class Redmine::I18nTest < ActiveSupport::TestCase | |||||
198 | assert_include [ja, "ja"], options |
|
198 | assert_include [ja, "ja"], options | |
199 | end |
|
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 | def test_locales_validness |
|
206 | def test_locales_validness | |
202 | lang_files_count = Dir["#{Rails.root}/config/locales/*.yml"].size |
|
207 | lang_files_count = Dir["#{Rails.root}/config/locales/*.yml"].size | |
203 | assert_equal lang_files_count, valid_languages.size |
|
208 | assert_equal lang_files_count, valid_languages.size |
General Comments 0
You need to be logged in to leave comments.
Login now