Module: Localize
- Defined in:
- lib/localize.rb,
lib/localize/formats.rb,
lib/localize/adapters/yaml.rb
Defined Under Namespace
Classes: Formats, MissString, Translation, YAMLadapter
Constant Summary
collapse
- @@default_locale =
:en
- @@locale =
@@default_locale
- @@store =
:yaml
- @@location =
''
Class Method Summary
collapse
Class Method Details
.default_locale ⇒ Object
98
99
100
|
# File 'lib/localize.rb', line 98
def default_locale
@@locale
end
|
.default_locale=(loc) ⇒ Object
93
94
95
96
|
# File 'lib/localize.rb', line 93
def default_locale=(loc)
reset!
@@locale = loc.to_sym
end
|
.load(locale = nil, location = nil) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/localize.rb', line 15
def load(locale=nil, location=nil)
@@locale = locale if locale
@@location = location if location
ret = case @@store
when :yaml
YAMLadapter.get_trans
when :plain
@@location
else
raise "Adapter not avalaible: #{adapter}"
end
@@trans = {
:text => Translation.new(ret['text']),
:formats => ret['formats']
}
end
|
.locale ⇒ Object
89
90
91
|
# File 'lib/localize.rb', line 89
def locale
@@locale
end
|
.locale=(loc) ⇒ Object
84
85
86
87
|
# File 'lib/localize.rb', line 84
def locale=(loc)
reset!
@@locale = loc
end
|
.localize(source, format = :full) ⇒ Object
Also known as:
l
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/localize.rb', line 38
def localize(source, format = :full)
load unless @@trans
if source.is_a?(Integer)
Formats.number(source)
elsif source.is_a?(Float)
Formats.number(source)
elsif source.is_a?(Time) or source.is_a?(Date)
Formats.date(source, format)
else
raise "Format not recognize"
end
end
|
.location ⇒ Object
107
108
109
|
# File 'lib/localize.rb', line 107
def location
@@location
end
|
.location=(locat) ⇒ Object
102
103
104
105
|
# File 'lib/localize.rb', line 102
def location=(locat)
reset!
@@location = locat
end
|
.phone(source, format = :full) ⇒ Object
Also known as:
f
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/localize.rb', line 54
def phone(source, format = :full)
load unless @@trans
fone = if source.is_a?(Integer)
source
elsif source.is_a?(String)
source.gsub(/[\+., -]/, '').trim.to_i
elsif source.is_a?(Float)
source.to_s.gsub('.', '').to_i
else
raise "Format not recognize"
end
Formats.phone(fone, format)
end
|
.reset! ⇒ Object
71
72
73
|
# File 'lib/localize.rb', line 71
def reset!
@@trans = nil
end
|
.store ⇒ Object
80
81
82
|
# File 'lib/localize.rb', line 80
def store
@@store
end
|
.store=(str) ⇒ Object
75
76
77
78
|
# File 'lib/localize.rb', line 75
def store=(str)
reset!
@@store = str.to_sym
end
|
.trans ⇒ Object
111
112
113
|
# File 'lib/localize.rb', line 111
def trans
@@trans
end
|
.translate ⇒ Object
33
34
35
36
|
# File 'lib/localize.rb', line 33
def translate
load unless @@trans
@@trans[:text]
end
|