Created
December 2, 2008 14:54
-
-
Save jasp/31133 to your computer and use it in GitHub Desktop.
Simple textmate script to convert an inline string to a translation string for use in Rails 2.2 i18n.
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}\"" | |
IO.popen("pbcopy", "w") { |copier| copier.puts translation } | |
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 | |
IO.popen("pbcopy", "w") { |copier| copier.puts translation } | |
# 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