Created
October 13, 2011 23:30
-
-
Save ddurdik/1285825 to your computer and use it in GitHub Desktop.
Script to convert un-localized text to yml keys
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
# Before: | |
# { bar, "Difficulty speaking", "How hard?", foo }, | |
# After: | |
# { bar, "difficulty_speaking", "how_hard", foo }, | |
def fix_key(bad_key) | |
bad_key.downcase.gsub(/[?:]/, '').gsub('/', ' ').gsub(' ', '_') | |
end | |
def fix_info(bad_info) | |
return "" unless bad_info | |
bad_info.downcase.gsub(/[?]/, '').gsub(' ', '_') | |
end | |
file_lines = %x{cat path/to/file.rb} | |
file_lines.each_line do |line| | |
match_data = line.match(/"{1}(.*)"{1}.*"{1}(.*)"{1}/) | |
if match_data | |
bad_key = match_data[1] | |
bad_info = match_data[2] | |
fixed_key = fix_key(bad_key) | |
fixed_info = fix_info(bad_info) | |
puts line.gsub(bad_key, fixed_key).gsub(bad_info, fixed_info) | |
else | |
puts line | |
next | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment