Last active
March 19, 2017 22:36
-
-
Save andrewyoo/fb5144c2f3a681389140bafe177664be to your computer and use it in GitHub Desktop.
Extract Copy from Rails Locale Files
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
h = {} | |
Dir.glob('config/locales/**/*.yml').each do |f| | |
h[f] = YAML.load(File.read(f)) | |
end | |
@lines = [] | |
def print_h(h) | |
h.each do |k,v| | |
if v.is_a? String | |
@lines << v | |
elsif v.is_a? Array | |
v.each do |row| | |
if row.is_a? String | |
@lines << row | |
else | |
print_h(row) | |
end | |
end | |
elsif v.is_a? Hash | |
print_h v | |
end | |
end | |
end | |
print_h(h) | |
@lines.uniq! # remove dups | |
@lines.reject! {|row| row.match(/\.(jpg|png|gif)/)} # remove pics | |
@lines.reject! {|row| row.match(/^http/)} # remove links | |
@lines.reject! {|row| row.match('_') && !row.match(' ')} # remove misc | |
@lines.reject! {|row| row.match('-') && !row.match(' ')} # remove more misc | |
@lines.reject! {|row| row.match(/^\//)} # remove paths | |
puts @lines | |
# then i did some manual cleanup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment