<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -6,7 +6,7 @@ require 'pstore'
 class Hash
   def deep_merge(other)
     # deep_merge by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
-    merger = proc { |key, v1, v2| Hash === v1 &amp;&amp; Hash === v2 ? v1.merge(v2, &amp;merger) : v2 }
+    merger = proc { |key, v1, v2| (Hash === v1 &amp;&amp; Hash === v2) ? v1.merge(v2, &amp;merger) : v2 }
     merge(other, &amp;merger)
   end
 
@@ -19,11 +19,23 @@ class Hash
       self[key].set keys, value
     end
   end
+
+  # copy of ruby's to_yaml method, prepending sort.
+  # before each so we get an ordered yaml file
+  def to_yaml( opts = {} )
+    YAML::quick_emit( self, opts ) do |out|
+      out.map( taguri, to_yaml_style ) do |map|
+        sort.each do |k, v| #&lt;- Adding sort.
+          map.add( k, v )
+        end
+      end
+    end
+  end
 end
 
 class Object
   def blank?
-    self.nil? || self.gsub(/\s/, '').empty? || self == false
+    self.nil? || self == false || (self.is_a?(String) &amp;&amp; self.gsub(/\s/, '').empty?)
   end
 end
 
@@ -62,9 +74,12 @@ class Translate
     end
 
     translation = ENV['TM_SELECTED_TEXT'].gsub(/^\s*(&quot;|')|(&quot;|')\s*$/, '')
-    self.add_plain_translation(key, translation)
-    self.add_yaml_translation(key, translation)
-    print replacement
+    if self.add_yaml_translation(key, translation)
+      self.add_plain_translation(key, translation)
+      print replacement
+    else
+      print @@original_text
+    end
   end
 
   def self.get_key
@@ -91,12 +106,36 @@ class Translate
   def self.add_yaml_translation(key, text)
     keys = ['en'] + key.split('.')
     data = { 'en' =&gt; {} }
-    data.set keys, text
+    data.set keys.dup, text
     if File.exists?(@@t_path_yaml)
       file_content = File.open(@@t_path_yaml, 'r') { |f| f.read }
-      data = data.deep_merge(YAML.load(file_content)) unless file_content.blank?
+      unless file_content.blank?
+        parsed_yaml = YAML.load(file_content)
+        return false unless self.confirm_if_key_already_in_use(keys, parsed_yaml, text)
+        data = parsed_yaml.deep_merge(data)
+      end
     end
     File.open(@@t_path_yaml, 'w+') { |f| f.write YAML.dump(data) }
+    true
+  end
+
+  def self.confirm_if_key_already_in_use(keys, data, text)
+    current_value = nil
+    begin
+      keys.each { |key| data = data[key] }
+      current_value = data unless data.blank?
+    rescue; end
+    confirmed = true
+    unless current_value.nil?
+      confirmed = TextMate::UI.request_confirmation :button1 =&gt; 'Overwrite', :button2 =&gt; 'Cancel',
+                                                    :title =&gt; 'You have already used this translation key',
+                                                    :prompt =&gt; &quot;This translation key is already in use.\n&quot; +
+                                                               &quot;It's current value is:\n&quot; +
+                                                               &quot;\t#{current_value}\n&quot; +
+                                                               &quot;Would you like to overwrite it with the follow?\n&quot; +
+                                                               &quot;\t#{text}&quot;
+    end
+    confirmed
   end
 
   def self.translation_method</diff>
      <filename>tools/Rails I18n.tmbundle/Support/lib/rails_i18n.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>62d6f0831c772690a6145711b1becfcb3b64fe37</id>
    </parent>
  </parents>
  <author>
    <name>Kieran Pilkington</name>
    <email>kieran@katipo.co.nz</email>
  </author>
  <url>http://github.com/svenfuchs/rails-i18n/commit/dbb7602d2e85ec43f95c483497a80693ad71dd77</url>
  <id>dbb7602d2e85ec43f95c483497a80693ad71dd77</id>
  <committed-date>2009-03-31T12:34:55-07:00</committed-date>
  <authored-date>2009-03-01T19:49:26-08:00</authored-date>
  <message>enhancement: sorting the translations file so it's easier to find the keys that were added (since previously they could show up anywhere). Also adding key collision checks. If you use a key already in use, it'll prompt you if you want to overwrite the old value. If you select Cancel, it'll exit out with nothing printed or logged.

Signed-off-by: Sven Fuchs &lt;svenfuchs@artweb-design.de&gt;</message>
  <tree>3d4ad131bb48cf8e582dd96d13e436d882c0f64a</tree>
  <committer>
    <name>Sven Fuchs</name>
    <email>svenfuchs@artweb-design.de</email>
  </committer>
</commit>
