Guest User

Untitled

a guest
Feb 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. $LOAD_PATH << "#{ENV["TM_SUPPORT_PATH"]}/lib"
  3. require 'ui'
  4. require 'escape'
  5. require 'exit_codes'
  6.  
  7. # Work on either selected text or current word
  8. text = ENV['TM_SELECTED_TEXT'] || ENV['TM_CURRENT_WORD']
  9. suggest = text.to_s.gsub(/::/, '/').
  10. gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  11. gsub(/([a-z\d])([A-Z])/,'\1_\2').
  12. tr("-", "_").
  13. downcase
  14.  
  15. # Get name of translation string
  16. name = TextMate::UI.request_string(:string => suggest, :prompt => "Type variable name")
  17.  
  18. if name.nil? or name == ""
  19. TextMate.exit_discard
  20. else
  21. translation = "#{name}: \"#{text}\""
  22.  
  23. # Copy string for en.yml to clipboard
  24. IO.popen("pbcopy", "w") { |copier| copier.puts translation }
  25. # Output with translation fetch
  26. print "<%=t '#{name}' %>"
  27. end
Add Comment
Please, Sign In to add comment