Skip to content

Instantly share code, notes, and snippets.

@etagwerker
Created February 25, 2011 12:29
Show Gist options
  • Save etagwerker/843719 to your computer and use it in GitHub Desktop.
Save etagwerker/843719 to your computer and use it in GitHub Desktop.
grepping in Ruby (crossplatform)
grep_output = ""
Dir.glob("public/**/**").select {|file| File.file?(file)}.each do |file|
File.open(file, 'r').each_with_index do |line, index|
grep_output += line if line.include?('I18n.t(') || line.include?('I18n.translate(')
end
end
result = []
result += grep_output.scan(/I18n\.t\('([\w+|\.+]+)'\)/) # captures I18n.t('a.key')
result += grep_output.scan(/I18n\.translate\('([\w+|\.+]+)'\)/) # captures I18n.t('a.key')
result += grep_output.scan(/I18n\.t\(\"([\w+|\.+]+)\"\)/) # captures I18n.t("a.key")
result += grep_output.scan(/I18n\.translate\(\"([\w+|\.+]+)\"\)/) # captures I18n.translate("a.key")
result.flatten
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment