matta-globalite 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +199 -0
- data/lang/rails/de-DE.yml +357 -0
- data/lang/rails/en-UK.yml +357 -0
- data/lang/rails/en-US.yml +357 -0
- data/lang/rails/es-AR.yml +355 -0
- data/lang/rails/es-ES.yml +357 -0
- data/lang/rails/fi-FI.yml +357 -0
- data/lang/rails/fr-FR.yml +359 -0
- data/lang/rails/hu-HU.yml +357 -0
- data/lang/rails/it.yml +358 -0
- data/lang/rails/nl-NL.yml +347 -0
- data/lang/rails/pl-PL.yml +358 -0
- data/lang/rails/pt-BR.yml +324 -0
- data/lang/rails/pt-PT.yml +324 -0
- data/lang/rails/ru-RU.yml +357 -0
- data/lang/rails/sr-CP.yml +357 -0
- data/lang/rails/sr-SR.yml +357 -0
- data/lang/rails/tr.yml +186 -0
- data/lang/rails/zh-CN.yml +357 -0
- data/lang/rails/zh-HK.yml +357 -0
- data/lang/rails/zh-TW.yml +357 -0
- data/lib/globalite.rb +26 -0
- data/lib/globalite/l10n.rb +300 -0
- data/lib/globalite/locale.rb +56 -0
- data/lib/rails/core_ext.rb +19 -0
- data/lib/rails/localization.rb +58 -0
- data/lib/rails/localized_action_view.rb +211 -0
- data/lib/rails/localized_active_record.rb +80 -0
- data/spec/core_localization_spec.rb +116 -0
- data/spec/helpers/spec_helper.rb +16 -0
- data/spec/l10n_spec.rb +251 -0
- data/spec/lang/rails/zz.yml +13 -0
- data/spec/lang/ui/en-UK.yml +3 -0
- data/spec/lang/ui/en-US.yml +3 -0
- data/spec/lang/ui/es.yml +3 -0
- data/spec/lang/ui/fr-FR.yml +8 -0
- metadata +87 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
class Locale
|
2
|
+
attr_reader :language, :country, :code
|
3
|
+
|
4
|
+
#
|
5
|
+
def self.language
|
6
|
+
Globalite.language
|
7
|
+
end
|
8
|
+
|
9
|
+
# Return the country
|
10
|
+
def self.country
|
11
|
+
Globalite.country
|
12
|
+
end
|
13
|
+
|
14
|
+
# Return the user's locale or the system's if the user doesn't have one set
|
15
|
+
def self.code
|
16
|
+
"#{Globalite.language}-#{Globalite.country}".to_sym
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
def self.set_code(locale)
|
21
|
+
if locale.to_s.split('-') && locale.to_s.length.between?(4,5) && Globalite.locales.include?(locale.to_sym)
|
22
|
+
Globalite.language = locale.to_s.split('-')[0].downcase.to_sym if locale.to_s.split('-')[0]
|
23
|
+
Globalite.country = locale.to_s.split('-')[1].upcase.to_sym if locale.to_s.split('-')[1]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.code=(locale)
|
28
|
+
self.set_code(locale)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Return the available locales
|
32
|
+
def self.codes
|
33
|
+
Globalite.locales
|
34
|
+
end
|
35
|
+
|
36
|
+
# Return the locale name in its own language for instance fr-FR => Français
|
37
|
+
def self.name(locale)
|
38
|
+
Globalite.locale_name(locale)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Return the list of the UI locales with their name
|
42
|
+
def self.ui_locales
|
43
|
+
Globalite.ui_locales
|
44
|
+
end
|
45
|
+
|
46
|
+
# Return the list of the Rails locales with their name
|
47
|
+
def self.rails_locales
|
48
|
+
Globalite.rails_locales
|
49
|
+
end
|
50
|
+
|
51
|
+
# Reset the Locale to the default settings
|
52
|
+
def self.reset!
|
53
|
+
Locale.set_code("#{Globalite.default_language}-#{Globalite.default_country}")
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SymbolExtension # :nodoc:
|
2
|
+
# Localizes the symbol into the current locale.
|
3
|
+
# If there is no translation available, the replacement string will be returned
|
4
|
+
def localize(replacement_string = '__localization_missing__', args={})
|
5
|
+
Globalite.localize(self, replacement_string, args)
|
6
|
+
end
|
7
|
+
alias :l :localize
|
8
|
+
|
9
|
+
def l_in(locale, args={})
|
10
|
+
Globalite.localize(self, '_localization_missing_', args, locale) unless locale.nil?
|
11
|
+
end
|
12
|
+
|
13
|
+
# Note that this method takes the replacement string after the args hash unlike other Globalite methods
|
14
|
+
def localize_with_args(args={}, replacement_string = '__localization_missing__')
|
15
|
+
Globalite.localize(self, replacement_string, args)
|
16
|
+
end
|
17
|
+
alias :l_with_args :localize_with_args
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
|
2
|
+
class Array
|
3
|
+
alias :orig_to_sentence :to_sentence
|
4
|
+
def to_sentence(options = {})
|
5
|
+
#Blend default options with sent through options
|
6
|
+
options.reverse_merge!({ :connector => :array_connector.l, :skip_last_comma => Boolean(:array_skip_last_comma.l) })
|
7
|
+
orig_to_sentence(options)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
class Time
|
13
|
+
# Acts the same as #strftime, but returns a localized version of the
|
14
|
+
# formatted date/time string.
|
15
|
+
def localize(format='default')
|
16
|
+
# unabashedly stolen from Globalize which unabashedly stole this snippet from Tadayoshi Funaba's Date class
|
17
|
+
o = ''
|
18
|
+
format = :date_helper_time_formats.l[format.to_s.downcase] if :date_helper_time_formats.l[format.to_s.downcase]
|
19
|
+
format.scan(/%[EO]?.|./o) do |c|
|
20
|
+
cc = c.sub(/^%[EO]?(.)$/o, '%\\1')
|
21
|
+
case cc
|
22
|
+
when '%A'; o << :date_helper_day_names.l[wday]
|
23
|
+
when '%a'; o << :date_helper_abbr_day_names.l[wday]
|
24
|
+
when '%B'; o << :date_helper_month_names.l[mon]
|
25
|
+
when '%b'; o << :date_helper_abbr_month_names.l[mon]
|
26
|
+
#when '%c'; o << :date_helper_time_formats.l[:default] ? :date_helper_date_formats.l[:default] : strftime('%Y-%m-%d')
|
27
|
+
when '%p'; o << if hour < 12 then :date_helper_am.l else :date_helper_pm.l end
|
28
|
+
else; o << c
|
29
|
+
end
|
30
|
+
end
|
31
|
+
strftime(o)
|
32
|
+
end
|
33
|
+
alias :l :localize
|
34
|
+
end
|
35
|
+
|
36
|
+
class Date
|
37
|
+
# Acts the same as #strftime, but returns a localized version of the formatted date string.
|
38
|
+
def localize(format='default')
|
39
|
+
# unabashedly stolen from Globalize which unabashedly stole this snippet from Tadayoshi Funaba's Date class
|
40
|
+
o = ''
|
41
|
+
format = :date_helper_date_formats.l[format.to_s.downcase] if :date_helper_date_formats.l[format.to_s.downcase]
|
42
|
+
format.scan(/%[EO]?.|./o) do |c|
|
43
|
+
cc = c.sub(/^%[EO]?(.)$/o, '%\\1')
|
44
|
+
case cc
|
45
|
+
when '%A'; o << :date_helper_day_names.l[wday]
|
46
|
+
when '%a'; o << :date_helper_abbr_day_names.l[wday]
|
47
|
+
when '%B'; o << :date_helper_month_names.l[mon]
|
48
|
+
when '%b'; o << :date_helper_abbr_month_names.l[mon]
|
49
|
+
#when '%c'; o << :date_helper_time_formats.l[:default] ? :date_helper_date_formats.l[:default] : strftime('%Y-%m-%d')
|
50
|
+
when '%p'; o << if hour < 12 then :date_helper_am.l else :date_helper_pm.l end
|
51
|
+
else; o << c
|
52
|
+
end
|
53
|
+
end
|
54
|
+
strftime(o)
|
55
|
+
end
|
56
|
+
alias :l :localize
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,211 @@
|
|
1
|
+
module ActionView
|
2
|
+
|
3
|
+
# Modify DateHelper to use localization keys
|
4
|
+
module Helpers
|
5
|
+
|
6
|
+
#Modify DateHelper distance_of_time_in_words
|
7
|
+
module DateHelper
|
8
|
+
|
9
|
+
def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false)
|
10
|
+
from_time = from_time.to_time if from_time.respond_to?(:to_time)
|
11
|
+
to_time = to_time.to_time if to_time.respond_to?(:to_time)
|
12
|
+
distance_in_minutes = (((to_time - from_time).abs)/60).round
|
13
|
+
distance_in_seconds = ((to_time - from_time).abs).round
|
14
|
+
|
15
|
+
case distance_in_minutes
|
16
|
+
when 0..1
|
17
|
+
return (distance_in_minutes==0) ? :date_helper_less_than_a_minute.l : :date_helper_one_minute.l unless include_seconds
|
18
|
+
case distance_in_seconds
|
19
|
+
when 0..5 then format( :date_helper_less_than_x_seconds.l , 5 )
|
20
|
+
when 6..10 then format( :date_helper_less_than_x_seconds.l , 10 )
|
21
|
+
when 11..20 then format( :date_helper_less_than_x_seconds.l , 20 )
|
22
|
+
when 21..40 then :date_helper_half_a_minute.l
|
23
|
+
when 41..59 then :date_helper_less_than_a_minute.l
|
24
|
+
else :date_helper_one_minute.l
|
25
|
+
end
|
26
|
+
|
27
|
+
when 2..44 then format(:date_helper_x_minutes.l, distance_in_minutes)
|
28
|
+
when 45..89 then :date_helper_one_hour.l
|
29
|
+
when 90..1439 then format( :date_helper_x_hours.l , (distance_in_minutes.to_f / 60.0).round )
|
30
|
+
when 1440..2879 then :date_helper_one_day.l
|
31
|
+
when 2880..43199 then format( :date_helper_x_days.l , (distance_in_minutes / 1440).round )
|
32
|
+
when 43200..86399 then :date_helper_one_month.l
|
33
|
+
when 86400..525959 then format( :date_helper_x_months.l , (distance_in_minutes / 43200).round )
|
34
|
+
when 525960..1051919 then :date_helper_one_year.l
|
35
|
+
else format( :date_helper_x_years.l , (distance_in_minutes / 525960).round )
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module NumberHelper
|
41
|
+
|
42
|
+
# modify number_to_currency to accept :order option
|
43
|
+
def number_to_currency(number, options = {})
|
44
|
+
# Blend default options with localized currency options
|
45
|
+
options.reverse_merge!({:unit => :number_helper_unit.l, :separator => :number_helper_separator.l, :delimiter => :number_helper_delimiter.l, :order => :number_helper_order.l})
|
46
|
+
options = options.stringify_keys
|
47
|
+
|
48
|
+
precision, unit, separator, delimiter = options.delete("precision") { 2 }, options.delete("unit") { "$" }, options.delete("separator") { "." }, options.delete("delimiter") { "," }
|
49
|
+
separator = "" unless precision > 0
|
50
|
+
|
51
|
+
#add leading space before trailing unit
|
52
|
+
unit = " " + unit if options["order"] == ['number', 'unit']
|
53
|
+
output = ''
|
54
|
+
begin
|
55
|
+
options["order"].each do |param|
|
56
|
+
case param
|
57
|
+
when 'unit'
|
58
|
+
output << unit
|
59
|
+
when 'number'
|
60
|
+
parts = number_with_precision(number, precision).split('.')
|
61
|
+
output << number_with_delimiter(parts[0], delimiter) + separator + parts[1].to_s
|
62
|
+
end
|
63
|
+
end
|
64
|
+
rescue
|
65
|
+
output = number
|
66
|
+
end
|
67
|
+
output
|
68
|
+
end
|
69
|
+
end# module NumberHelper
|
70
|
+
|
71
|
+
module DateHelper
|
72
|
+
|
73
|
+
# Blend default options with localized :order option and add locale support
|
74
|
+
# Example:
|
75
|
+
# <% form_for(@page) do |f| %>
|
76
|
+
# <p>
|
77
|
+
# <b><%= :published_date.l_in(@locale) %></b><br />
|
78
|
+
# <%= f.date_select :published_date, :locale => @locale %>
|
79
|
+
# </p>
|
80
|
+
#
|
81
|
+
def date_select(object_name, method, options = {})
|
82
|
+
if options[:locale]
|
83
|
+
@original_locale = Locale.code
|
84
|
+
Locale.code = options[:locale]
|
85
|
+
end
|
86
|
+
options.reverse_merge!( :order => :date_helper_order.l )
|
87
|
+
@selector = InstanceTag.new(object_name, method, self, nil, options.delete(:object)).to_date_select_tag(options)
|
88
|
+
Locale.code = @original_locale if options[:locale]
|
89
|
+
return @selector
|
90
|
+
end
|
91
|
+
|
92
|
+
# Blend default options with localized :order option
|
93
|
+
# Look at date_select for an usage example
|
94
|
+
def datetime_select(object_name, method, options = {})
|
95
|
+
if options[:locale]
|
96
|
+
@original_locale = Locale.code
|
97
|
+
Locale.code = options[:locale]
|
98
|
+
end
|
99
|
+
options.reverse_merge!( :order => :date_helper_order.l )
|
100
|
+
@selector = InstanceTag.new(object_name, method, self, nil, options.delete(:object)).to_datetime_select_tag(options)
|
101
|
+
Locale.code = @original_locale if options[:locale]
|
102
|
+
return @selector
|
103
|
+
end
|
104
|
+
|
105
|
+
def select_month(date, options = {}, html_options = {})
|
106
|
+
if options[:locale]
|
107
|
+
@original_locale = Locale.code
|
108
|
+
Locale.code = options[:locale]
|
109
|
+
end
|
110
|
+
val = date ? (date.kind_of?(Fixnum) ? date : date.month) : ''
|
111
|
+
if options[:use_hidden]
|
112
|
+
@selector = hidden_html(options[:field_name] || 'month', val, options)
|
113
|
+
else
|
114
|
+
month_options = []
|
115
|
+
monthnames = :date_helper_month_names.l
|
116
|
+
abbr_monthnames = :date_helper_abbr_month_names.l
|
117
|
+
month_names = options[:use_month_names] || (options[:use_short_month] ? abbr_monthnames : monthnames)
|
118
|
+
month_names.unshift(nil) if month_names.size < 13
|
119
|
+
1.upto(12) do |month_number|
|
120
|
+
month_name = if options[:use_month_numbers]
|
121
|
+
month_number
|
122
|
+
elsif options[:add_month_numbers]
|
123
|
+
month_number.to_s + ' - ' + month_names[month_number]
|
124
|
+
else
|
125
|
+
month_names[month_number]
|
126
|
+
end
|
127
|
+
|
128
|
+
month_options << ((val == month_number) ?
|
129
|
+
%(<option value="#{month_number}" selected="selected">#{month_name}</option>\n) :
|
130
|
+
%(<option value="#{month_number}">#{month_name}</option>\n)
|
131
|
+
)
|
132
|
+
end
|
133
|
+
@selector = select_html(options[:field_name] || 'month', month_options, options)
|
134
|
+
end
|
135
|
+
Locale.code = @original_locale if options[:locale]
|
136
|
+
return @selector
|
137
|
+
end
|
138
|
+
|
139
|
+
end #module DateHelper
|
140
|
+
|
141
|
+
|
142
|
+
module FormOptionsHelper
|
143
|
+
|
144
|
+
def country_options_for_select(selected = nil, priority_countries = nil)
|
145
|
+
country_options = ""
|
146
|
+
|
147
|
+
if priority_countries
|
148
|
+
country_options += options_for_select(priority_countries, selected)
|
149
|
+
country_options += "<option value=\"\">-------------</option>\n"
|
150
|
+
end
|
151
|
+
|
152
|
+
if priority_countries && priority_countries.include?(selected)
|
153
|
+
country_options += options_for_select(:countries_list.l - priority_countries, selected)
|
154
|
+
else
|
155
|
+
country_options += options_for_select(:countries_list.l, selected)
|
156
|
+
end
|
157
|
+
|
158
|
+
return country_options
|
159
|
+
end
|
160
|
+
|
161
|
+
end #module FormOptionsHelper
|
162
|
+
|
163
|
+
module ActiveRecordHelper
|
164
|
+
def error_messages_for(*params)
|
165
|
+
options = params.extract_options!.symbolize_keys
|
166
|
+
if object = options.delete(:object)
|
167
|
+
objects = [object].flatten
|
168
|
+
else
|
169
|
+
objects = params.collect {|object_name| instance_variable_get("@#{object_name}") }.compact
|
170
|
+
end
|
171
|
+
count = objects.inject(0) {|sum, object| sum + object.errors.count }
|
172
|
+
unless count.zero?
|
173
|
+
html = {}
|
174
|
+
[:id, :class].each do |key|
|
175
|
+
if options.include?(key)
|
176
|
+
value = options[key]
|
177
|
+
html[key] = value unless value.blank?
|
178
|
+
else
|
179
|
+
html[key] = 'errorExplanation'
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
options[:object_name] ||= params.first
|
184
|
+
|
185
|
+
original_failed_object = options[:object_name].to_s.gsub('_', ' ')
|
186
|
+
failed_object = options[:object_name].l(original_failed_object)
|
187
|
+
|
188
|
+
original_header_message = "#{pluralize(count, 'error')} prohibited this #{original_failed_object} from being saved"
|
189
|
+
header_message = :active_record_helper_header_message.l_with_args({:error_count => count, :failed_object => failed_object }, original_header_message)
|
190
|
+
message = :active_record_helper_error_description.l('There were problems with the following fields:')
|
191
|
+
|
192
|
+
# Fix for :header_message and :message values if present
|
193
|
+
# It works just like regular rails functionality
|
194
|
+
options[:header_message] = header_message unless options.include?(:header_message)
|
195
|
+
options[:message] = message unless options.include?(:message)
|
196
|
+
error_messages = objects.map {|object| object.errors.full_messages.map {|msg| content_tag(:li, msg) } }
|
197
|
+
|
198
|
+
contents = ''
|
199
|
+
contents << content_tag(options[:header_tag] || :h2, options[:header_message]) unless options[:header_message].blank?
|
200
|
+
contents << content_tag(:p, options[:message]) unless options[:message].blank?
|
201
|
+
contents << content_tag(:ul, error_messages)
|
202
|
+
|
203
|
+
content_tag(:div, contents, html)
|
204
|
+
else
|
205
|
+
''
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end #module ActiveRecordHelper
|
209
|
+
|
210
|
+
end #module Helpers
|
211
|
+
end #module ActionView
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
class Errors
|
3
|
+
|
4
|
+
# Error messages modified in lang file
|
5
|
+
@@default_error_messages.update({
|
6
|
+
:inclusion => :error_message_inclusion.l,
|
7
|
+
:exclusion => :error_message_exclusion.l,
|
8
|
+
:invalid => :error_message_invalid.l,
|
9
|
+
:confirmation => :error_message_confirmation.l,
|
10
|
+
:accepted => :error_message_accepted.l,
|
11
|
+
:empty => :error_message_empty.l,
|
12
|
+
:blank => :error_message_blank.l,
|
13
|
+
:too_long => :error_message_too_long.l,
|
14
|
+
:too_short => :error_message_too_short.l,
|
15
|
+
:wrong_length => :error_message_wrong_length.l,
|
16
|
+
:taken => :error_message_taken.l,
|
17
|
+
:not_a_number => :error_message_not_a_number.l,
|
18
|
+
})
|
19
|
+
|
20
|
+
# Reloads the localization
|
21
|
+
def self.relocalize
|
22
|
+
@@default_error_messages.update({
|
23
|
+
:inclusion => :error_message_inclusion.l,
|
24
|
+
:exclusion => :error_message_exclusion.l,
|
25
|
+
:invalid => :error_message_invalid.l,
|
26
|
+
:confirmation => :error_message_confirmation.l,
|
27
|
+
:accepted => :error_message_accepted.l,
|
28
|
+
:empty => :error_message_empty.l,
|
29
|
+
:blank => :error_message_blank.l,
|
30
|
+
:too_long => :error_message_too_long.l,
|
31
|
+
:too_short => :error_message_too_short.l,
|
32
|
+
:wrong_length => :error_message_wrong_length.l,
|
33
|
+
:taken => :error_message_taken.l,
|
34
|
+
:not_a_number => :error_message_not_a_number.l,
|
35
|
+
})
|
36
|
+
end
|
37
|
+
|
38
|
+
# Redefine the ActiveRecord::Errors::full_messages method:
|
39
|
+
# Returns all the full error messages in an array. 'Base' messages are handled as usual.
|
40
|
+
# Non-base messages are prefixed with the attribute name as usual UNLESS they begin with '^'
|
41
|
+
# in which case the attribute name is omitted.
|
42
|
+
# E.g. validates_acceptance_of :accepted_terms, :message => '^Please accept the terms of service'
|
43
|
+
#
|
44
|
+
#
|
45
|
+
# If field name has the same key like in language yaml file, its replaced by its corresponding language file value.
|
46
|
+
# This fixes the problem of translating validation messages but not field names. Now you can fully localize them.
|
47
|
+
# E.g. validates_presence_of :name
|
48
|
+
# produces (in en-UK and pl-PL:
|
49
|
+
# Name can't be empty
|
50
|
+
# Nazwa jest wymagana
|
51
|
+
# By convetion yaml language key falue for field is the same as ActiveRecords model field name
|
52
|
+
# If plugin can't find such key, it behaves just like without plugin.
|
53
|
+
def full_messages
|
54
|
+
full_messages = []
|
55
|
+
|
56
|
+
@errors.each_key do |attr|
|
57
|
+
@errors[attr].each do |msg|
|
58
|
+
next if msg.nil?
|
59
|
+
|
60
|
+
if attr == "base"
|
61
|
+
full_messages << msg
|
62
|
+
elsif msg =~ /^\^/
|
63
|
+
full_messages << msg[1..-1]
|
64
|
+
else
|
65
|
+
full_messages << attr.intern.l(attr) + " " + msg
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
return full_messages
|
71
|
+
end
|
72
|
+
|
73
|
+
# # Handle model error localization
|
74
|
+
# def add(attribute, msg = @@default_error_messages[:invalid])
|
75
|
+
# @errors[attribute.l] = [] if @errors[attribute.to_s].nil?
|
76
|
+
# @errors[attribute.l] << msg
|
77
|
+
# end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# This examples can only be run if the plugin is installed in a Rails app
|
2
|
+
# Requires RSpec plugin or gem
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/helpers/spec_helper'
|
5
|
+
include ActionView::Helpers::DateHelper
|
6
|
+
include ActionView::Helpers::NumberHelper
|
7
|
+
include ActionView::Helpers::FormOptionsHelper
|
8
|
+
|
9
|
+
describe "when Rails is loaded" do
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
Globalite.current_locale = 'en-US'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have loaded fr" do
|
16
|
+
Globalite.locales.should include(:"fr-FR")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have loaded the rails localization file in English and French" do
|
20
|
+
:error_message_inclusion.l.should == "is not included in the list"
|
21
|
+
Globalite.locale = :"fr-FR"
|
22
|
+
Globalite.locales.should include(:"fr-FR")
|
23
|
+
Globalite.locale.should == :"fr-FR"
|
24
|
+
Globalite.localizations.keys.should include(:error_message_inclusion)
|
25
|
+
Globalite.localizations[:error_message_inclusion].should_not be(nil)
|
26
|
+
:error_message_inclusion.l.should == "n'est pas inclus dans la liste."
|
27
|
+
end
|
28
|
+
|
29
|
+
it "ActiveRecord error messages should be localized in English" do
|
30
|
+
ActiveRecord::Errors.default_error_messages[:confirmation].should include("doesn't match confirmation")
|
31
|
+
Globalite.current_language = :fr
|
32
|
+
ActiveRecord::Errors.default_error_messages[:confirmation].should include("ne correspond pas à la confirmation")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "distance_of_time_in_words should be localized properly" do
|
36
|
+
from = Time.mktime(2004, 3, 6, 21, 41, 18).utc
|
37
|
+
distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 41, 25).utc).should == "less than a minute"
|
38
|
+
distance_of_time_in_words(Time.mktime(2004, 3, 7, 1, 20).utc, from).should == "about 4 hours"
|
39
|
+
Globalite.language = :fr
|
40
|
+
distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 41, 25).utc).should == "moins d'une minute"
|
41
|
+
distance_of_time_in_words(Time.mktime(2004, 3, 7, 1, 20).utc, from).should == "environ 4 heures"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "currency should be localized" do
|
45
|
+
number_to_currency(123).should == "$123.00"
|
46
|
+
Globalite.current_language = :fr
|
47
|
+
number_to_currency(123).should == "123,00 €"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should support different locales" do
|
51
|
+
Globalite.current_locale = :"en-US"
|
52
|
+
number_to_currency(123).should == "$123.00"
|
53
|
+
Globalite.current_locale = :"en-UK"
|
54
|
+
number_to_currency(123).should == "£123.00"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "date_select should be localized" do
|
58
|
+
select_day(Time.parse("Sat Aug 16 07:00:00 UTC 2003")).should == %Q(<select id=\"date_day\" name=\"date[day]\">\n<option value=\"1\">1</option>\n<option value=\"2\">2</option>\n<option value=\"3\">3</option>\n<option value=\"4\">4</option>\n<option value=\"5\">5</option>\n<option value=\"6\">6</option>\n<option value=\"7\">7</option>\n<option value=\"8\">8</option>\n<option value=\"9\">9</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option selected=\"selected\" value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n<option value=\"24\">24</option>\n<option value=\"25\">25</option>\n<option value=\"26\">26</option>\n<option value=\"27\">27</option>\n<option value=\"28\">28</option>\n<option value=\"29\">29</option>\n<option value=\"30\">30</option>\n<option value=\"31\">31</option>\n</select>\n)
|
59
|
+
select_day(Time.parse("Sat Aug 16 07:00:00 UTC 2003"), :include_blank => true).should == %Q(<select id="date_day" name="date[day]">\n<option value=""></option>\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option selected="selected" value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n)
|
60
|
+
select_day(16, :include_blank => true).should == %Q(<select id="date_day" name="date[day]">\n<option value=""></option>\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option selected="selected" value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n)
|
61
|
+
Globalite.current_language = :fr
|
62
|
+
select_day(Time.parse("Sat Aug 16 07:00:00 UTC 2003")).should == %Q(<select id=\"date_day\" name=\"date[day]\">\n<option value=\"1\">1</option>\n<option value=\"2\">2</option>\n<option value=\"3\">3</option>\n<option value=\"4\">4</option>\n<option value=\"5\">5</option>\n<option value=\"6\">6</option>\n<option value=\"7\">7</option>\n<option value=\"8\">8</option>\n<option value=\"9\">9</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option selected=\"selected\" value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n<option value=\"24\">24</option>\n<option value=\"25\">25</option>\n<option value=\"26\">26</option>\n<option value=\"27\">27</option>\n<option value=\"28\">28</option>\n<option value=\"29\">29</option>\n<option value=\"30\">30</option>\n<option value=\"31\">31</option>\n</select>\n)
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
it "datetime_select should be localized" do
|
67
|
+
select_datetime(nil, :prefix => "date[first]").should include('January')
|
68
|
+
Globalite.language = :fr
|
69
|
+
select_datetime(nil, :prefix => "date[first]").should include('Janvier')
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#select_month' do
|
73
|
+
it "should localize the month's names and their abbreviations" do
|
74
|
+
select_month(Time.mktime(2003, 8, 16)).should == %Q(<select id=\"date_month\" name=\"date[month]\">\n<option value=\"1\">January</option>\n<option value=\"2\">February</option>\n<option value=\"3\">March</option>\n<option value=\"4\">April</option>\n<option value=\"5\">May</option>\n<option value=\"6\">June</option>\n<option value=\"7\">July</option>\n<option value=\"8\" selected=\"selected\">August</option>\n<option value=\"9\">September</option>\n<option value=\"10\">October</option>\n<option value=\"11\">November</option>\n<option value=\"12\">December</option>\n</select>\n)
|
75
|
+
Globalite.language = :fr
|
76
|
+
select_month(Time.mktime(2003, 8, 16)).should == %Q(<select id=\"date_month\" name=\"date[month]\">\n<option value=\"1\">Janvier</option>\n<option value=\"2\">Février</option>\n<option value=\"3\">Mars</option>\n<option value=\"4\">Avril</option>\n<option value=\"5\">Mai</option>\n<option value=\"6\">Juin</option>\n<option value=\"7\">Juillet</option>\n<option value=\"8\" selected=\"selected\">Août</option>\n<option value=\"9\">Septembre</option>\n<option value=\"10\">Octobre</option>\n<option value=\"11\">Novembre</option>\n<option value=\"12\">Décembre</option>\n</select>\n)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should support the :use_hidden option" do
|
80
|
+
select_month(Time.mktime(2003, 8, 16), :use_hidden => true).should == %Q(<input id=\"date_month\" name=\"date[month]\" type=\"hidden\" value=\"8\" />\n)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it "the country list should be localized" do
|
85
|
+
expected_en = %Q(<option value=\"Afghanistan\">Afghanistan</option>\n<option value=\"Albania\">Albania</option>\n<option value=\"Algeria\">Algeria</option>\n<option value=\"American Samoa\">American Samoa</option>\n<option value=\"Andorra\">Andorra</option>\n<option value=\"Angola\">Angola</option>\n<option value=\"Anguilla\">Anguilla</option>\n<option value=\"Antarctica\">Antarctica</option>\n<option value=\"Antigua And Barbuda\">Antigua And Barbuda</option>\n<option value=\"Argentina\">Argentina</option>\n<option value=\"Armenia\">Armenia</option>\n<option value=\"Aruba\">Aruba</option>\n<option value=\"Australia\">Australia</option>\n<option value=\"Austria\">Austria</option>\n<option value=\"Azerbaijan\")
|
86
|
+
country_options_for_select.should include(expected_en)
|
87
|
+
Globalite.current_language = :fr
|
88
|
+
expected_fr = %Q(<option value=\"Afghanistan\">Afghanistan</option>\n<option value=\"Albanie\">Albanie</option>\n<option value=\"Algérie\">Algérie</option>\n)
|
89
|
+
country_options_for_select.should include(expected_fr)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'time should be localized' do
|
93
|
+
t = Time.parse('2006-12-25 13:55 UTC')
|
94
|
+
t.to_formatted_s(:long).should == 'December 25, 2006 13:55'
|
95
|
+
Globalite.language = :fr
|
96
|
+
t.l(:long).should == '25 Décembre, 2006 13:55'
|
97
|
+
t.l(:short).should == '25 Déc, 13:55'
|
98
|
+
# custom format
|
99
|
+
t.l('%a, %A, %d %b %B %Y %H:%M:%S %p').should == "Lun, Lundi, 25 Déc Décembre 2006 13:55:00 pm"
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'date should be localized' do
|
103
|
+
d = Date.new(2007,05,13)
|
104
|
+
d.l.should == '2007-05-13'
|
105
|
+
Globalite.current_language = :fr
|
106
|
+
d.l(:short).should == '13 Mai'
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'an array to sentence should be localized' do
|
110
|
+
us = ['Heidi', 'Matt']
|
111
|
+
us.to_sentence.should == 'Heidi and Matt'
|
112
|
+
Globalite.current_language = :fr
|
113
|
+
us.to_sentence.should == 'Heidi et Matt'
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|