Skip to content

Instantly share code, notes, and snippets.

@astashov
Created January 21, 2009 07:40
Show Gist options
  • Save astashov/49888 to your computer and use it in GitHub Desktop.
Save astashov/49888 to your computer and use it in GitHub Desktop.
DeGlobalite (if you want to uninstall globalite plugin) the Rails app - change back all :something.l and :smthg.l_with_args(:a => "a") to 'Something' and 'Smthg a'
File.open("lang/ui/en-US.yml") do |file|
while line = file.gets
sym, translate = line.split(":", 2)
Dir['app/views/*/**', 'app/controllers/*', 'app/helpers/*'].each do |path|
lines = ""
File.open( path ) do |f|
lines = f.readlines
end
changes = false
lines_changed = []
lines.each_with_index do |line, index|
if match = line.match(/:#{sym}\.l_with_args\((.*)\)/)
values = match[1]
values = values.split(",").map { |v| v.strip }
replaces = {}
values.each do |value|
pair = value.split('=>').map { |v| v.strip }
replaces[pair[0].gsub(':', '')] = pair[1]
end
replaces.each do |key, value|
translate.gsub!("{#{key}}", '#{' + value + '}')
end
changes = true
line.gsub!(/:#{sym}.l_with_args\(.*\)/, "\"#{translate.strip.gsub(/^['"]/, '').gsub(/['"]$/, '')}\"")
lines_changed << (index + 1)
elsif line.match(/:#{sym}\.l/)
changes = true
translate = translate.strip.gsub(/^['"]/, '').gsub(/['"]$/, '')
line.gsub!(/:#{sym}.l/, "\"#{translate}\"")
lines_changed << (index + 1)
end
end
if changes
File.open(path, 'w') do |f|
lines.each do |line|
f.write(line)
end
puts "#{path} file was changed in lines: #{lines_changed.join(", ")}"
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment