mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 15:20:13 +01:00
17 lines
529 B
Ruby
17 lines
529 B
Ruby
task :rewrite_locales_utf8 do
|
|
require 'base64'
|
|
Dir[Rails.root.join("config/locales/*.yml")].each do |path|
|
|
content = File.read(path)
|
|
content.force_encoding('utf-8')
|
|
content.gsub! /\\x([A-Fa-f0-9]{2})/ do |hex|
|
|
Integer(hex[2..3], 16).chr
|
|
end
|
|
content.gsub! /!binary \|\n\s+(.+?)\n\n/m do |match|
|
|
decoded = Base64.decode64($1)
|
|
decoded.gsub! /"/, '\\"'
|
|
"\"#{decoded}\"\n"
|
|
end
|
|
content = content.force_encoding('utf-8')
|
|
File.open(path, 'w') { |f| f.write content }
|
|
end
|
|
end
|