Configure language of events

This commit is contained in:
Ana 2016-03-21 00:18:20 +01:00
parent ad0a8eecf2
commit 6c87995050
16 changed files with 115 additions and 16 deletions

View file

@ -52,6 +52,7 @@ class Program < ActiveRecord::Base
before_create :create_event_types
before_create :create_difficulty_levels
validate :check_languages_format
##
# Checcks if the program has rating enabled
@ -83,6 +84,10 @@ class Program < ActiveRecord::Base
(!conference.email_settings.program_schedule_public_subject.blank? && !conference.email_settings.program_schedule_public_body.blank?)
end
def languages_list
self.languages.split(',').map {|l| ISO_639.find(l).english_name} if self.languages.present?
end
private
##
@ -113,4 +118,20 @@ class Program < ActiveRecord::Base
color: '#EF6E69')
true
end
##
# Check if languages string has the right format. Used as validation.
#
def check_languages_format
return unless self.languages.present?
# All white spaces are removed to allow languages to be separated by ',' and ', '. The languages string without spaces is saved
self.languages = self.languages.delete(' ').downcase
errors.add(:languages, 'must be two letters separated by commas') && return unless
self.languages.match(/^$|(\A[a-z][a-z](,[a-z][a-z])*\z)/).present?
languages_array = self.languages.split(',')
# We check that languages are not repeated
errors.add(:languages, "can't be repeated") && return unless languages_array.uniq!.nil?
# We check if every language is a valid ISO 639-1 language
errors.add(:languages, 'must be ISO 639-1 valid codes') unless languages_array.select{ |x| ISO_639.find(x).nil? }.empty?
end
end