Skip to content

Instantly share code, notes, and snippets.

@armahillo
armahillo / i18n.rake
Created July 5, 2022 05:30
Rails task that identifies text that should be extracted to localization files
# I wrote this up one evening while auditing an app for localization. It can almost certainly be optimized, but it works!
namespace :i18n do
# This method is doing most of the heavy lifting. It accepts a full filename with path and returns
# a hash of arrays, where each key is one of the different groupings
def scan_file_for_literals file_with_path
file = File.read(file_with_path)
# First off, omit any straight ruby code that isn't emitted, since it won't need to be localized
file.gsub! /^<%[^=].*%>/m, ''