Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
- IO.popen("pbcopy", "w") { |copier| copier.puts translation }
- # Output with translation fetch
- print "<%=t '#{name}' %>"
- end
Add Comment
Please, Sign In to add comment