From 4a9587fa23e6d95561e2d2d6309f4f9f0e78d9d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Thu, 9 Apr 2015 17:04:14 +0200 Subject: [PATCH] FIX: auto-load all plugin locales so that they can be used in PrettyText --- config/application.rb | 5 +++-- lib/pretty_text.rb | 9 +++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/config/application.rb b/config/application.rb index 2f72b3a8268..400a4e50d43 100644 --- a/config/application.rb +++ b/config/application.rb @@ -88,8 +88,9 @@ module Discourse # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. config.time_zone = 'UTC' - # auto-load server locale in plugins - config.i18n.load_path += Dir["#{Rails.root}/plugins/*/config/locales/server.*.yml"] + # auto-load locales in plugins + # NOTE: we load both client & server locales since some might be used by PrettyText + config.i18n.load_path += Dir["#{Rails.root}/plugins/*/config/locales/*.yml"] # Configure the default encoding used in templates for Ruby 1.9. config.encoding = 'utf-8' diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index 9e0c9672a52..e298ca9e8b7 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -12,11 +12,11 @@ module PrettyText def t(key, opts) key = "js." + key unless opts - return I18n.t(key) + I18n.t(key) else str = I18n.t(key, Hash[opts.entries].symbolize_keys).dup - opts.each {|k,v| str.gsub!("{{#{k.to_s}}}", v.to_s) } - return str + opts.each { |k,v| str.gsub!("{{#{k.to_s}}}", v.to_s) } + str end end @@ -26,7 +26,6 @@ module PrettyText user = User.find_by(username_lower: username.downcase) return "" unless user.present? - # TODO: Add support for ES6 and call `avatar-template` directly if !user.uploaded_avatar_id && SiteSetting.default_avatars.present? split_avatars = SiteSetting.default_avatars.split("\n") @@ -147,7 +146,6 @@ module PrettyText context.eval("Discourse.SiteSettings = #{SiteSetting.client_settings_json};") context.eval("Discourse.CDN = '#{Rails.configuration.action_controller.asset_host}';") context.eval("Discourse.BaseUrl = 'http://#{RailsMultisite::ConnectionManagement.current_hostname}';") - context.eval("Discourse.getURL = function(url) { return '#{Discourse::base_uri}' + url };") context.eval("Discourse.getURLWithCDN = function(url) { url = Discourse.getURL(url); if (Discourse.CDN) { url = Discourse.CDN + url; } return url; };") end @@ -166,7 +164,6 @@ module PrettyText context_opts = opts || {} context_opts[:sanitize] ||= true context['opts'] = context_opts - context['raw'] = text if Post.white_listed_image_classes.present?