Project

General

Profile

« Previous | Next » 

Revision eab8e5a0

Added by Marc Dequènes about 14 years ago

  • ID eab8e5a03df426fc8a87c422a5e31bcb4478b4ba

[fix] clarify language/locale in I18nController

View differences:

lib/cyborghood/base/language.rb
@config = Config.instance
end
def available_languages
def available_locales
list = ['en'] + Dir.new(Config::L10N_DIR).select{|d| File.directory?(File.join(Config::L10N_DIR, d)) and d[0..0] != "." }
# local admin can restrict available languages
# local admin can restrict available locales
# (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 = list & @config.i18n.restricted_locale_set if @config.i18n.restricted_locale_set
list = ['en'] if list.empty?
list
end
def set_language(lang)
set_locale_all(lang)
def set_locale(locale)
set_locale_all(locale)
end
def set_default_language
set_language('en')
def set_default_locale
set_locale('en')
end
def set_language_for_user(user)
def set_locale_for_user(user)
if user.nil?
set_default_language
set_default_locale
elsif user.preferredLanguage.nil?
logger.debug "User has no language preference, using default"
set_default_language
set_default_locale
else
logger.debug "User preference for language: " + user.preferredLanguage
lang = user.prefered_language(self.available_languages)
if lang.nil?
locale = user.prefered_language(self.available_locales)
if locale.nil?
logger.debug "No available language fits the user preference, using english"
lang = 'en'
set_default_locale
else
logger.debug "Language better fitting user preference: " + lang
logger.debug "Language better fitting user preference: " + locale
set_locale(locale)
end
set_language(lang)
end
end
end

Also available in: Unified diff