translate zones

This commit is contained in:
Emi Matchu 2013-01-26 09:54:29 -06:00
parent 964a64e0c8
commit 361b5df256
2 changed files with 37 additions and 1 deletions

View file

@ -23,6 +23,6 @@ class Zone < ActiveRecord::Base
end end
def self.plainify_label(label) def self.plainify_label(label)
label.delete('\- /').downcase label.delete('\- /').parameterize
end end
end end

36
lib/tasks/translate.rake Normal file
View file

@ -0,0 +1,36 @@
require 'rocketamf/remote_gateway'
namespace :translate do
def with_given_locale
I18n.with_locale(ENV['LOCALE']) do
language_code = I18n.neopets_language_code_for(I18n.locale)
unless language_code
raise "Locale #{I18n.locale.inspect} has no neopets language code"
end
yield(language_code)
end
end
desc "Download the Neopets zone data for the given locale"
task :zones => :environment do
with_given_locale do |neopets_language_code|
gateway = RocketAMF::RemoteGateway.new(Pet::GATEWAY_URL)
action = gateway.service('CustomPetService').action('getApplicationData')
envelope = action.request([]).post(
:headers => {
'Cookie' => "lang=#{neopets_language_code}"
}
)
application_data = envelope.messages[0].data.body
zones_by_id = Zone.all.inject({}) { |h, z| h[z.id] = z ; h}
application_data[:zones].each do |zone_data|
zone = zones_by_id[zone_data[:id].to_i]
zone.label = zone_data[:label]
zone.plain_label = Zone.plainify_label(zone.label)
zone.save!
end
end
end
end