Skip to content

Instantly share code, notes, and snippets.

@andrewyoo
Last active March 19, 2017 22:36
Show Gist options
  • Save andrewyoo/fb5144c2f3a681389140bafe177664be to your computer and use it in GitHub Desktop.
Save andrewyoo/fb5144c2f3a681389140bafe177664be to your computer and use it in GitHub Desktop.
Extract Copy from Rails Locale Files
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