autoload server/client locales in plugins

This commit is contained in:
Régis Hanol
2013-11-19 16:42:28 +01:00
parent f9e8d57acf
commit 291acca4fa
3 changed files with 24 additions and 22 deletions
+14 -17
View File
@@ -9,11 +9,6 @@ class DiscoursePluginRegistry
attr_accessor :stylesheets
# Default accessor values
#
def stylesheets
@stylesheets ||= Set.new
end
def javascripts
@javascripts ||= Set.new
end
@@ -21,13 +16,15 @@ class DiscoursePluginRegistry
def server_side_javascripts
@server_side_javascripts ||= Set.new
end
end
def stylesheets
@stylesheets ||= Set.new
end
end
def register_js(filename, options={})
# If we have a server side option, add that too.
self.class.server_side_javascripts << options[:server_side] if options[:server_side].present?
self.class.javascripts << filename
end
@@ -35,26 +32,26 @@ class DiscoursePluginRegistry
self.class.stylesheets << filename
end
def stylesheets
self.class.stylesheets
end
def register_archetype(name, options={})
Archetype.register(name, options)
end
def server_side_javascripts
self.class.javascripts
end
def javascripts
self.class.javascripts
end
def server_side_javascripts
self.class.server_side_javascripts
end
def stylesheets
self.class.stylesheets
end
def self.clear
self.stylesheets = nil
self.server_side_javascripts = nil
self.javascripts = nil
self.server_side_javascripts = nil
self.stylesheets = nil
end
def self.setup(plugin_class)
+8 -1
View File
@@ -1,10 +1,17 @@
module JsLocaleHelper
def self.output_locale(locale, translations = nil)
locale_str = locale.to_s
# load default translations
translations ||= YAML::load(File.open("#{Rails.root}/config/locales/client.#{locale_str}.yml"))
# load plugins translations
plugin_translations = {}
Dir["#{Rails.root}/plugins/*/config/locales/client.#{locale_str}.yml"].each do |file|
plugin_translations.merge! YAML::load(File.open(file))
end
# merge translations (plugin translations overwrite default translations)
translations[locale_str]['js'].merge!(plugin_translations[locale_str]['js'])
# We used to split the admin versus the client side, but it's much simpler to just
# include both for now due to the small size of the admin section.