Project

General

Profile

« Previous | Next » 

Revision 83a04d84

Added by Marc Dequènes over 15 years ago

  • ID 83a04d84853f5c0bbc497d4d1865859c15471058

[evol] added language selection in the Person through a new I18n class providing the link between local available languages and user preferences in the database

View differences:

bin/postman
result_tag = report.ok? ? "SUCCESS" : "FAILURE"
logger.info "Processing result: #{result_tag} (#{report.error})"
if report.user
if report.user.preferredLanguage
logger.debug "User preference for langage: " + report.user.preferredLanguage
set_locale(report.user.preferredLanguage)
else
logger.debug "No user preference for langage, using english"
set_locale("en")
end
else
set_locale("en")
end
i18n = I18n.instance
i18n.set_language_for_user(report.user)
unless report.ok?
if report.warn_sender
lib/cyborghood/base.rb
return new_conf
end
end
class I18n
include Singleton
def initialize
@config = Config.instance
end
def available_languages
list = ['en'] + Dir.new(L10N_DIR).select{|d| File.directory?(d) and d[0..0] != "." }
# local admin can restrict available languages
# (may be useful if l10n is partial due to third party plugins)
list = list & @config.i18n.restricted_language_set if @config.i18n.restricted_language_set
list = ['en'] if list.empty?
list
end
def set_language(lang)
set_locale(lang)
end
def set_default_language
set_language('en')
end
def set_language_for_user(user)
if user.nil?
set_default_language
else
logger.debug "User preference for language: " + user.preferredLanguage
lang = user.prefered_language(self.available_languages)
if lang.nil?
logger.debug "No available langage fits the user preference, using english"
lang = 'en'
else
logger.debug "Language better fitting user preference: " + lang
end
set_language(lang)
end
end
end
end
lib/cyborghood/objects.rb
require 'cyborghood/base'
require 'delegate'
require 'cyborghood/objects/ldap'
require 'http_headers'
module CyborgHood
class DnsDomain < Delegator
......
raise CyberError.new(:unrecoverable, "db/ldap", e.message)
end
def prefered_language(available_languages)
lang_chooser = HTTPHeaders::AcceptLanguage.parse(self.preferredLanguage)
ordered_list = lang_chooser.reduce(available_languages)
ordered_list.empty? ? nil : ordered_list.first.range
end
def __getobj__
@ldap
end

Also available in: Unified diff