forked from pedromtavares/universitas
/
localized_system.rb
47 lines (34 loc) · 888 Bytes
/
localized_system.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module LocalizedSystem
extend ActiveSupport::Memoizable
module ClassMethods
def disable_locale
skip_before_filter :set_locale
before_filter :set_locale_to_default
end
end
def self.included( base )
base.before_filter :set_locale
base.helper_method :current_locale, :t, :l
base.extend( LocalizedSystem::ClassMethods )
end
def t( *args )
I18n.t(*args)
end
def l( *args )
I18n.l(*args)
end
def set_locale_to_default
I18n.locale = I18n.default_locale
end
def set_locale
I18n.locale = cookies.permanent[:locale] = params[:locale] || cookies[:locale] || I18n.default_locale
current_user.update_attribute(:locale, I18n.locale) unless current_user.blank?
end
def current_locale
I18n.locale
end
memoize :current_locale
def change_locale( locale )
cookies.permanent[:locale] = locale
end
end