Browse Source

Improved notification i18n() replacements.

Martin Edenhofer 10 years ago
parent
commit
4a8a167300

+ 1 - 0
db/seeds.rb

@@ -1938,6 +1938,7 @@ Translation.create_if_not_exists( :locale => 'de', :source => "to", :target => "
 Translation.create_if_not_exists( :locale => 'de', :source => "%s ago", :target => "vor %s" )
 Translation.create_if_not_exists( :locale => 'de', :source => "in %s", :target => "in %s" )
 Translation.create_if_not_exists( :locale => 'de', :source => "Mark all as seen.", :target => "Alle als gelesen markieren." )
+Translation.create_if_not_exists( :locale => 'de', :source => "Pending till", :target => "Warten bis" )
 #Translation.create_if_not_exists( :locale => 'de', :source => "", :target => "" )
 
 # install all packages in auto_install

+ 1 - 1
lib/notification_factory.rb

@@ -80,7 +80,7 @@ module NotificationFactory
     }
 
     # translate
-    data[:string].gsub!( /i18n\((.+?)\)/ ) { |placeholder|
+    data[:string].gsub!( /i18n\((|.+?)\)/ ) { |placeholder|
       string      = $1
       locale      = data[:locale] || 'en'
       placeholder = Translation.translate( locale, string )

+ 15 - 0
test/unit/notification_factory_test.rb

@@ -126,6 +126,21 @@ class NotificationFactoryTest < ActiveSupport::TestCase
         :string => '\#{puts `ls`}',
         :result => '\#{puts `ls`} (not allowed)',
       },
+      {
+        :locale => 'de',
+        :string => 'test i18n(new)',
+        :result => 'test neu',
+      },
+      {
+        :locale => 'de',
+        :string => 'test i18n()',
+        :result => 'test ',
+      },
+      {
+        :locale => 'de',
+        :string => 'test i18n(new) i18n(open)',
+        :result => 'test neu offen',
+      },
     ]
     tests.each { |test|
       result = NotificationFactory.build(

+ 17 - 2
test/unit/ticket_notification_test.rb

@@ -406,16 +406,21 @@ class TicketNotificationTest < ActiveSupport::TestCase
       :article_id => article.id,
       :type       => 'update',
       :changes    => {
-        :priority_id => [1, 2],
+        :priority_id  => [1, 2],
+        :pending_time => [nil, Time.parse("2015-01-11 23:33:47 UTC")],
       },
     )
 
     # check changed attributes
     human_changes = bg.human_changes(agent1,ticket1)
     assert( human_changes['Priority'], 'Check if attributes translated based on ObjectManager::Attribute' )
+    assert( human_changes['Pending till'], 'Check if attributes translated based on ObjectManager::Attribute' )
     assert_equal( 'i18n(1 low)', human_changes['Priority'][0] )
     assert_equal( 'i18n(2 normal)', human_changes['Priority'][1] )
+    assert_equal( 'i18n()', human_changes['Pending till'][0] )
+    assert_equal( 'i18n(2015-01-11 23:33:47 UTC)', human_changes['Pending till'][1] )
     assert_not( human_changes['priority_id'] )
+    assert_not( human_changes['pending_till'] )
 
     # en template
     template = bg.template_update(agent2, ticket1, article, human_changes)
@@ -424,6 +429,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
     assert_match( /Priority/, template[:body] )
     assert_match( /1 low/, template[:body] )
     assert_match( /2 normal/, template[:body] )
+    assert_match( /Pending till/, template[:body] )
+    assert_match( /2015-01-11 23:33:47 UTC/, template[:body] )
     assert_match( /updated/i, template[:subject] )
 
     # en notification
@@ -449,7 +456,10 @@ class TicketNotificationTest < ActiveSupport::TestCase
     assert_match( /Priority/, body )
     assert_match( /1 low/, body )
     assert_match( /2 normal/, body )
+    assert_match( /Pending till/, body )
+    assert_match( /2015-01-11 23:33:47 UTC/, body )
     assert_match( /update/, body )
+    assert_no_match( /i18n/, body )
 
     # de template
     template = bg.template_update(agent1, ticket1, article, human_changes)
@@ -458,6 +468,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
     assert_match( /Priority/, template[:body] )
     assert_match( /1 low/, template[:body] )
     assert_match( /2 normal/, template[:body] )
+    assert_match( /Pending till/, template[:body] )
+    assert_match( /2015-01-11 23:33:47 UTC/, template[:body] )
     assert_match( /aktualis/, template[:subject] )
 
     # de notification
@@ -484,7 +496,10 @@ class TicketNotificationTest < ActiveSupport::TestCase
     assert_match( /Priorität/, body )
     assert_match( /1 niedrig/, body )
     assert_match( /2 normal/, body )
+    assert_match( /Warten/, body )
+    assert_match( /2015-01-11 23:33:47 UTC/, body )
     assert_match( /aktualis/, body )
+    assert_no_match( /i18n/, body )
 
     bg = Observer::Ticket::Notification::BackgroundJob.new(
       :ticket_id  => ticket1.id,
@@ -500,7 +515,7 @@ class TicketNotificationTest < ActiveSupport::TestCase
     puts "hc #{human_changes.inspect}"
 
 
-   human_changes = bg.human_changes(agent2,ticket1)
+    human_changes = bg.human_changes(agent2,ticket1)
     puts "hc2 #{human_changes.inspect}"
 
     template = bg.template_update(agent1, ticket1, article, human_changes)