Skip to content

Commit

Permalink
Fix i18n spec
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Nov 24, 2017
1 parent 4a12a66 commit 0c44f7b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/redmine/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,13 @@ def all_languages
##
# Returns the given language if it is valid or nil otherwise.
def find_language(lang)
return nil unless lang =~ /[a-z-]+/i
valid_languages.detect { |l| l =~ /#{lang}/i } if lang.present?
return nil unless (lang.present? && lang =~ /[a-z-]+/i)

# Direct match
direct_match = valid_languages.detect { |l| l =~ /^#{lang}$/i }
parent_match = valid_languages.detect { |l| l =~ /#{lang}/i }

direct_match || parent_match
end

def set_language_if_valid(lang)
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/redmine/i18n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module OpenProject

# it is OK if more languages exist
it 'has a language for every language file' do
lang_files_count = Dir.glob(Rails.root.join('config/locales/*.yml'))
lang_files_count = Dir.glob(Rails.root.join('config/locales/**/*.yml'))
.map { |f| File.basename(f) }
.reject { |b| b.starts_with? 'js' }
.size
Expand Down

0 comments on commit 0c44f7b

Please sign in to comment.