From 4a8a1673009d04f5d20c2b16a306d39dc0d7c7a6 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 10 Feb 2015 15:59:21 +0100 Subject: [PATCH] Improved notification i18n() replacements. --- db/seeds.rb | 1 + lib/notification_factory.rb | 2 +- test/unit/notification_factory_test.rb | 15 +++++++++++++++ test/unit/ticket_notification_test.rb | 19 +++++++++++++++++-- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 7f8e21d1f..bd6a03ea5 100644 --- a/db/seeds.rb +++ b/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 diff --git a/lib/notification_factory.rb b/lib/notification_factory.rb index c91cf15de..54c9edefb 100644 --- a/lib/notification_factory.rb +++ b/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 ) diff --git a/test/unit/notification_factory_test.rb b/test/unit/notification_factory_test.rb index d335ed138..90a4da020 100644 --- a/test/unit/notification_factory_test.rb +++ b/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( diff --git a/test/unit/ticket_notification_test.rb b/test/unit/ticket_notification_test.rb index 688031a82..8ccafbb03 100644 --- a/test/unit/ticket_notification_test.rb +++ b/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)