Forked from jasp/Convert to translated with translation in clipboard.tmCommand
Created
March 7, 2009 05:02
-
-
Save cquaker/75233 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| <plist version="1.0"> | |
| <dict> | |
| <key>beforeRunningCommand</key> | |
| <string>nop</string> | |
| <key>command</key> | |
| <string>#!/usr/bin/ruby | |
| $LOAD_PATH << "#{ENV["TM_SUPPORT_PATH"]}/lib" | |
| require 'ui' | |
| require 'escape' | |
| require 'exit_codes' | |
| text = ENV['TM_SELECTED_TEXT'] || ENV['TM_CURRENT_WORD'] | |
| suggest = text.to_s.gsub(/::/, '/'). | |
| gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). | |
| gsub(/([a-z\d])([A-Z])/,'\1_\2'). | |
| tr("-", "_"). | |
| downcase | |
| name = TextMate::UI.request_string(:string => suggest, :prompt => "Type variable name") | |
| if name.nil? or name == "" | |
| TextMate.exit_discard | |
| else | |
| translation = "#{name}: \"#{text}\"" | |
| %x{echo #{e_sh translation} | pbcopy} | |
| print "<%=t '#{name}' %>" | |
| end</string> | |
| <key>fallbackInput</key> | |
| <string>word</string> | |
| <key>input</key> | |
| <string>selection</string> | |
| <key>keyEquivalent</key> | |
| <string>^T</string> | |
| <key>name</key> | |
| <string>Convert to translated with translation in clipboard</string> | |
| <key>output</key> | |
| <string>replaceSelectedText</string> | |
| <key>scope</key> | |
| <string>text.html.ruby</string> | |
| <key>uuid</key> | |
| <string>F79A298F-8E4F-4DEC-9D6D-F59F833977B3</string> | |
| </dict> | |
| </plist> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/ruby | |
| $LOAD_PATH << "#{ENV["TM_SUPPORT_PATH"]}/lib" | |
| require 'ui' | |
| require 'escape' | |
| require 'exit_codes' | |
| # Work on either selected text or current word | |
| text = ENV['TM_SELECTED_TEXT'] || ENV['TM_CURRENT_WORD'] | |
| suggest = text.to_s.gsub(/::/, '/'). | |
| gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). | |
| gsub(/([a-z\d])([A-Z])/,'\1_\2'). | |
| tr("-", "_"). | |
| downcase | |
| # Get name of translation string | |
| name = TextMate::UI.request_string(:string => suggest, :prompt => "Type variable name") | |
| if name.nil? or name == "" | |
| TextMate.exit_discard | |
| else | |
| translation = "#{name}: \"#{text}\"" | |
| # Copy string for en.yml to clipboard | |
| %x{echo #{e_sh translation} | pbcopy} | |
| # Output with translation fetch | |
| print "<%=t '#{name}' %>" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment