mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 07:40:12 +01:00
added script to rewrite locales utf8
This commit is contained in:
parent
bd8498f39c
commit
017e1761ca
1 changed files with 17 additions and 0 deletions
17
lib/tasks/rewrite_locales_utf8.rake
Normal file
17
lib/tasks/rewrite_locales_utf8.rake
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue