2013-08-23 17:35:01 -04:00
|
|
|
require_dependency 'enum_site_setting'
|
|
|
|
|
|
|
|
class LocaleSiteSetting < EnumSiteSetting
|
2013-06-11 11:39:55 -04:00
|
|
|
|
|
|
|
def self.valid_value?(val)
|
|
|
|
supported_locales.include?(val)
|
|
|
|
end
|
|
|
|
|
2013-06-23 01:07:25 -04:00
|
|
|
def self.values
|
2013-08-23 17:35:01 -04:00
|
|
|
supported_locales.map do |l|
|
2016-09-07 18:04:01 -04:00
|
|
|
lang = language_names[l] || language_names[l[0..1]]
|
2017-07-27 21:20:09 -04:00
|
|
|
{ name: lang ? lang['nativeName'] : l, value: l }
|
2013-08-23 17:35:01 -04:00
|
|
|
end
|
2013-06-11 11:39:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
@lock = Mutex.new
|
|
|
|
|
2016-09-07 18:04:01 -04:00
|
|
|
def self.language_names
|
|
|
|
return @language_names if @language_names
|
|
|
|
|
|
|
|
@lock.synchronize do
|
|
|
|
@language_names ||= YAML.load(File.read(File.join(Rails.root, 'config', 'locales', 'names.yml')))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-11 11:39:55 -04:00
|
|
|
def self.supported_locales
|
|
|
|
@lock.synchronize do
|
2017-07-27 21:20:09 -04:00
|
|
|
@supported_locales ||= Dir.glob(File.join(Rails.root, 'config', 'locales', 'client.*.yml')).map { |x| x.split('.')[-2] }.sort
|
2013-06-11 11:39:55 -04:00
|
|
|
end
|
|
|
|
end
|
2014-10-03 23:07:20 -04:00
|
|
|
|
2013-06-11 11:39:55 -04:00
|
|
|
end
|