Project

General

Profile

« Previous | Next » 

Revision 4c969e21

Added by Marc Dequènes about 14 years ago

  • ID 4c969e21f0acc2a3d27c1c707dbc2a7917caf455

[evol] select and record I18n locale in DSL Task (future use)

View differences:

bin/test_client
pp errors
pp results
puts "Tadam: " + (results[:info1][:api_version] == results[:info2][:api_version] ? "same" : "different")
set_preferred_locales "fr;q=1,en-us,en"
meet "waiter", :zzz
STDOUT.flush
on_success do
lib/cyborghood/base/language.rb
include Singleton
include GetText
DEFAULT_LOCALE = "en"
def initialize
@config = Config.instance
end
......
end
def set_default_locale
set_locale('en')
set_locale(DEFAULT_LOCALE)
end
def set_locale_for_user(user)
lib/cyborghood/cyborg/dsl.rb
#++
require 'active_support/basic_object'
require 'http_headers'
require 'set'
......
end
class TaskBase < BaseDSL
attr_reader :bot, :name, :errors, :results
attr_reader :bot, :name, :errors, :results, :preferred_locales, :locale
@@task_wip = 0
......
@results = {}.freeze
@notification_name = "task/#{@name}"
@preferred_locales = nil
@locale = nil
_setup
_start_dsl &block
end
def set_preferred_locales(prefs)
_add_subtask("setting/preferred_locales") do |subtask|
logger.debug "Task '#{@name}': setting preferred locales"
lang_chooser = HTTPHeaders::AcceptLanguage.parse(prefs)
if lang_chooser
@preferred_locales = prefs
ordered_list = lang_chooser.reduce(I18nController.instance.available_locales)
@locale = ordered_list.empty? ? I18nController::DEFAULT_LOCALE : ordered_list.first.range
logger.debug "Task '#{@name}': locale chosen: #{@locale}"
else
@errors << CyberError.new(:unrecoverable, "botnet/client/dsl", _("unparsable preferred locales"))
end
subtask.finish
end
end
# may return a Hash of results
def schedule(&job)
_add_subtask("job/#{job.hash}") do |subtask|

Also available in: Unified diff