2013-08-23 16:35:01 -05:00
|
|
|
require_dependency 'enum_site_setting'
|
|
|
|
|
|
|
|
class LocaleSiteSetting < EnumSiteSetting
|
2013-06-11 10:39:55 -05:00
|
|
|
|
|
|
|
def self.valid_value?(val)
|
|
|
|
supported_locales.include?(val)
|
|
|
|
end
|
|
|
|
|
2013-06-23 00:07:25 -05:00
|
|
|
def self.values
|
2013-08-23 16:35:01 -05:00
|
|
|
supported_locales.map do |l|
|
2016-09-07 17:04:01 -05:00
|
|
|
lang = language_names[l] || language_names[l[0..1]]
|
2017-07-27 20:20:09 -05:00
|
|
|
{ name: lang ? lang['nativeName'] : l, value: l }
|
2013-08-23 16:35:01 -05:00
|
|
|
end
|
2013-06-11 10:39:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
@lock = Mutex.new
|
|
|
|
|
2016-09-07 17:04:01 -05: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 10:39:55 -05:00
|
|
|
def self.supported_locales
|
|
|
|
@lock.synchronize do
|
2017-11-15 10:20:04 -06:00
|
|
|
@supported_locales ||= begin
|
|
|
|
app_client_files = Dir.glob(
|
|
|
|
File.join(Rails.root, 'config', 'locales', 'client.*.yml')
|
|
|
|
)
|
|
|
|
|
2017-11-15 11:50:20 -06:00
|
|
|
unless Rails.env.test? && ENV['LOAD_PLUGINS'] != "1"
|
|
|
|
app_client_files += Dir.glob(
|
|
|
|
File.join(Rails.root, 'plugins', '*', 'config', 'locales', 'client.*.yml')
|
|
|
|
)
|
|
|
|
end
|
2017-11-15 10:20:04 -06:00
|
|
|
|
2017-11-15 11:50:20 -06:00
|
|
|
app_client_files.map { |x| x.split('.')[-2] }.uniq.sort
|
2017-11-15 10:20:04 -06:00
|
|
|
end
|
2013-06-11 10:39:55 -05:00
|
|
|
end
|
|
|
|
end
|
2014-10-03 22:07:20 -05:00
|
|
|
|
2013-06-11 10:39:55 -05:00
|
|
|
end
|