From c49731a91baf61db44bf3968d17c9c413c428179 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 16 Jul 2013 17:48:48 +1000 Subject: [PATCH] fix failing server side quote localisation change --- lib/pretty_text.rb | 14 ++++++++++++++ spec/components/pretty_text_spec.rb | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index bcb6d790ba8..7c3f74498a0 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -46,6 +46,19 @@ module PrettyText class Helpers + + def t(key, opts) + str = I18n.t("js." + key) + if opts + # TODO: server localisation has no parity with client + # should be fixed + opts.each do |k,v| + str.gsub!("{{#{k}}}", v) + end + end + str + end + # function here are available to v8 def avatar_template(username) return "" unless username @@ -90,6 +103,7 @@ module PrettyText @ctx.eval("var Discourse = {}; Discourse.SiteSettings = #{SiteSetting.client_settings_json};") @ctx.eval("var window = {}; window.devicePixelRatio = 2;") # hack to make code think stuff is retina + @ctx.eval("var I18n = {}; I18n.t = function(a,b){ return helpers.t(a,b); }"); ctx_load( "app/assets/javascripts/discourse/components/bbcode.js", "app/assets/javascripts/discourse/components/utilities.js", diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index cc0f38e094e..a30dcd5a5f9 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -15,15 +15,15 @@ test end it "produces a quote even with new lines in it" do - PrettyText.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]ddd\n[/quote]").should match_html "

" + PrettyText.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]ddd\n[/quote]").should match_html "

" end it "should produce a quote" do - PrettyText.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]ddd[/quote]").should match_html "

" + PrettyText.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]ddd[/quote]").should match_html "

" end it "trims spaces on quote params" do - PrettyText.cook("[quote=\"EvilTrout, post:555, topic: 666\"]ddd[/quote]").should match_html "

" + PrettyText.cook("[quote=\"EvilTrout, post:555, topic: 666\"]ddd[/quote]").should match_html "

" end