Revision 83a04d84
Added by Marc Dequènes over 15 years ago
- ID 83a04d84853f5c0bbc497d4d1865859c15471058
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
|
Also available in: Unified diff
[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