cs-german_l10n 0.1.1

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/MIT-LICENCE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Christoph Schiessl
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the GermanL10n plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the GermanL10n plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'GermanL10n'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
data/TODO ADDED
@@ -0,0 +1,8 @@
1
+ 1. Test Suite is incomplete (ActiveRecord and ActionView tests)
2
+
3
+ 2. Upgrade to Rails 2.2.0 when released.
4
+ See http://www.artweb-design.de/2008/7/18/the-ruby-on-rails-i18n-core-api
5
+
6
+ 3. README File (Installation and Usage)
7
+
8
+ 4. Does Date/Time format localization influence log files?
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'german_l10n'
@@ -0,0 +1,401 @@
1
+ module GermanL10n
2
+ class ActiveRecord
3
+ ErrorMessages = {
4
+ # :inclusion => "is not included in the list"
5
+ :inclusion => "ist nicht in der Liste gültiger Optionen enthalten",
6
+ # :exclusion => "is reserved"
7
+ :exclusion => "ist reserviert",
8
+ # :invalid => "is invalid"
9
+ :invalid => "ist ungültig",
10
+ # :confirmation => "doesn't match confirmation"
11
+ :confirmation => "entspricht nicht der Bestätigung",
12
+ # :accepted => "must be accepted"
13
+ :accepted => "muss akzeptiert werden",
14
+ # :empty => "can't be empty"
15
+ :empty => "darf nicht leer sein",
16
+ # :blank => "can't be blank"
17
+ :blank => "muss angegeben werden",
18
+ # :too_long => "is too long (maximum is %d characters)"
19
+ :too_long => "ist zu lang (höchstens %d Zeichen)",
20
+ # :too_short => "is too short (minimum is %d characters)"
21
+ :too_short => "ist zu kurz (mindestens %d Zeichen)",
22
+ # :wrong_length => "is the wrong length (should be %d characters)"
23
+ :wrong_length => "hat eine falsche Länge (sollte %d Zeichen lang sein)",
24
+ # :taken => "has already been taken"
25
+ :taken => "ist schon vergeben",
26
+ # :not_a_number => "is not a number"
27
+ :not_a_number => "ist keine Zahl",
28
+ # :greater_than => "must be greater than %d"
29
+ :greater_than => "muss größer als %d sein",
30
+ # :greater_than_or_equal_to => "must be greater than or equal to %d"
31
+ :greater_than_or_equal_to => "muss größer oder gleich %d sein",
32
+ # :equal_to => "must be equal to %d"
33
+ :equal_to => "muss gleich %d sein",
34
+ # :less_than => "must be less than %d"
35
+ :less_than => "muss kleiner als %d sein",
36
+ # :less_than_or_equal_to => "must be less than or equal to %d"
37
+ :less_than_or_equal_to => "muss kleiner oder gleich %d sein",
38
+ # :odd => "must be odd"
39
+ :odd => "muss ungerade sein",
40
+ # :even => "must be even"
41
+ :even => "muss gerade sein",
42
+
43
+ # Not included in Default ActiveRecord:
44
+ :error_translation => "Fehler",
45
+ :error_header => "%s hinderte %s daran, gespeichert zu werden",
46
+ :error_subheader => "Es gab folgende Probleme: "
47
+ }
48
+ end
49
+
50
+ class DateHelper
51
+ Texts = {
52
+ :less_than_x_seconds => "weniger als %d Sekunden",
53
+ :half_a_minute => "eine halbe Minute",
54
+ :less_than_a_minute => "weniger als eine Minute",
55
+ :one_minute => "eine Minute",
56
+ :x_minutes => "%d Minuten",
57
+ :one_hour => "ungefähr eine Stunde",
58
+ :x_hours => "ungefähr %d Stunden",
59
+ :one_day => "ein Tag",
60
+ :x_days => "%d Tage",
61
+ :one_month => "ein Monat",
62
+ :x_months => "%d Monate",
63
+ :one_year => "ein Jahr",
64
+ :x_years => "%d Jahre"
65
+ }
66
+
67
+ Monthnames = [nil] + %w{Januar Februar März April Mai Juni Juli August September Oktober November Dezember}
68
+ AbbrMonthnames = [nil] + %w{Jan Feb Mrz Apr Mai Jun Jul Aug Sep Okt Nov Dez}
69
+ Daynames = %w{Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag}
70
+ AbbrDaynames = %w{So Mo Di Mi Do Fr Sa}
71
+
72
+ DateFormats = {
73
+ # :default => "%Y-%m-%d"
74
+ :default => "%e. %m. %Y",
75
+ # :short => "%e %b"
76
+ :short => "%e. %b.",
77
+ # :long => "%B %e, %Y"
78
+ :long => "%A, %e. %B %Y",
79
+ # :db => "%Y-%m-%d"
80
+ # :number => "%Y%m%d"
81
+ # :long_ordinal => lambda { |date| date.strftime("%B #{date.day.ordinalize}, %Y") }
82
+ :long_ordinal => "%A, %e. %B %Y" # not used in german
83
+ # :rfc822 => "%e %b %Y"
84
+ }
85
+
86
+ TimeFormats = {
87
+ # :default => "%Y-%m-%dT%H:%M:%S%Z",
88
+ :default => "%A, %e. %B %Y %H:%M %Z",
89
+ # :db => "%Y-%m-%d %H:%M:%S"
90
+ # :number => "%Y%m%d%H%M%S"
91
+ # :time => "%H:%M"
92
+ # :short => "%d %b %H:%M"
93
+ :short => "%e. %b. %H:%M",
94
+ # :long => "%B %d, %Y %H:%M"
95
+ :long => "%A, %e. %B %Y, %H:%M",
96
+ # :long_ordinal => lambda { |time| time.strftime("%B #{time.day.ordinalize}, %Y %H:%M") }
97
+ :long_ordinal => "%A, %e. %B %Y, %H:%M" # not used in german
98
+ # :rfc822 => "%a, %d %b %Y %H:%M:%S %z"
99
+ }
100
+
101
+ DateSelectOrder = { :order => [:day, :month, :year] }
102
+ end
103
+
104
+ class NumberHelper
105
+ CurrencyOptions = {
106
+ # :unit => "$"
107
+ :unit => "€",
108
+ # :separator => "."
109
+ :separator => ",",
110
+ # :delimiter => ","
111
+ :delimiter => ".",
112
+ # :order => [:number, :unit]
113
+ :order => [:unit, :number]
114
+ }
115
+ end
116
+
117
+ class ArrayHelper
118
+ ToSentenceTexts = {
119
+ # :connector => 'and'
120
+ :connector => 'und',
121
+ # :skip_last_comma => false
122
+ :skip_last_comma => true
123
+ }
124
+ end
125
+
126
+ def self.localize_strftime(date = '%d.%m.%Y', time = '')
127
+ ignore = "\xFF\xFF\xFF\xFF" # %% == Literal "%" character
128
+ date.gsub!(/%%/, ignore)
129
+ date.gsub!(/%a/, GermanL10n::DateHelper::AbbrDaynames[time.wday])
130
+ date.gsub!(/%A/, GermanL10n::DateHelper::Daynames[time.wday])
131
+ date.gsub!(/%b/, GermanL10n::DateHelper::AbbrMonthnames[time.mon])
132
+ date.gsub!(/%B/, GermanL10n::DateHelper::Monthnames[time.mon])
133
+ date.gsub!(ignore, '%%')
134
+ end
135
+ end
136
+
137
+ ActiveSupport::Inflector.inflections do |inflect|
138
+ inflect.uncountable "fehler"
139
+ end
140
+
141
+ module ActiveRecord
142
+ class Errors
143
+ @@default_error_messages.update(GermanL10n::ActiveRecord::ErrorMessages)
144
+ end
145
+ end
146
+
147
+ module ActionView
148
+ module Helpers
149
+ module ActiveRecordHelper
150
+ alias_method :old_error_messages_for, :error_messages_for
151
+
152
+ # def error_messages_for(*params)
153
+ # options = params.extract_options!.symbolize_keys
154
+ # if object = options.delete(:object)
155
+ # objects = [object].flatten
156
+ # else
157
+ # objects = params.collect {|object_name| instance_variable_get("@#{object_name}") }.compact
158
+ # end
159
+ # count = objects.inject(0) {|sum, object| sum + object.errors.count }
160
+ # unless count.zero?
161
+ # html = {}
162
+ # [:id, :class].each do |key|
163
+ # if options.include?(key)
164
+ # value = options[key]
165
+ # html[key] = value unless value.blank?
166
+ # else
167
+ # html[key] = 'errorExplanation'
168
+ # end
169
+ # end
170
+ # options[:object_name] ||= params.first
171
+ # options[:header_message] = "#{pluralize(count, 'error')} prohibited this #{options[:object_name].to_s.gsub('_', ' ')} from being saved" unless options.include?(:header_message)
172
+ # options[:message] ||= 'There were problems with the following fields:' unless options.include?(:message)
173
+ # error_messages = objects.sum {|object| object.errors.full_messages.map {|msg| content_tag(:li, msg) } }.join
174
+ #
175
+ # contents = ''
176
+ # contents << content_tag(options[:header_tag] || :h2, options[:header_message]) unless options[:header_message].blank?
177
+ # contents << content_tag(:p, options[:message]) unless options[:message].blank?
178
+ # contents << content_tag(:ul, error_messages)
179
+ #
180
+ # content_tag(:div, contents, html)
181
+ # else
182
+ # ''
183
+ # end
184
+ # end
185
+
186
+ def error_messages_for(*params)
187
+ options = params.last.is_a?(Hash) ? params.pop.symbolize_keys : {}
188
+ objects = params.collect {|object_name| instance_variable_get("@#{object_name}") }.compact
189
+ count = objects.inject(0) {|sum, object| sum + object.errors.count }
190
+ unless count.zero?
191
+ html = {}
192
+ [:id, :class].each do |key|
193
+ if options.include?(key)
194
+ value = options[key]
195
+ html[key] = value unless value.blank?
196
+ else
197
+ html[key] = 'errorExplanation'
198
+ end
199
+ end
200
+ messages = ActiveRecord::Errors.default_error_messages
201
+ header_message = format(messages[:error_header], pluralize(count, messages[:error_translation]), (options[:object_name] || params.first).to_s.gsub("_", " "))
202
+ error_messages = objects.map { |object| object.errors.full_messages.map { |msg| content_tag(:li, msg) } }
203
+ content_tag(:div,
204
+ content_tag(options[:header_tag] || :h2, header_message) <<
205
+ content_tag(:p, messages[:error_subheader]) <<
206
+ content_tag(:ul, error_messages),
207
+ html
208
+ )
209
+ else
210
+ ''
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end
216
+
217
+ module ActionView
218
+ module Helpers
219
+ module NumberHelper
220
+ alias_method :orig_number_to_currency, :number_to_currency
221
+
222
+ # def number_to_currency(number, options = {})
223
+ # options = options.stringify_keys
224
+ # precision = options["precision"] || 2
225
+ # unit = options["unit"] || "$"
226
+ # separator = precision > 0 ? options["separator"] || "." : ""
227
+ # delimiter = options["delimiter"] || ","
228
+ # format = options["format"] || "%u%n"
229
+ #
230
+ # begin
231
+ # parts = number_with_precision(number, precision).split('.')
232
+ # format.gsub(/%n/, number_with_delimiter(parts[0], delimiter) + separator + parts[1].to_s).gsub(/%u/, unit)
233
+ # rescue
234
+ # number
235
+ # end
236
+ # end
237
+
238
+ def number_to_currency(number, options = {})
239
+ options.reverse_merge!(GermanL10n::NumberHelper::CurrencyOptions)
240
+ options[:order] ||= [:unit, :number]
241
+ options = options.stringify_keys
242
+ precision, unit = options.delete("precision") { 2 }, options.delete("unit") { "$" }
243
+ separator, delimiter = options.delete("separator") { "." }, options.delete("delimiter") { "," }
244
+ separator = "" unless precision > 0
245
+ unit = " " + unit if options["order"] == [:number, :unit]
246
+ output = ''
247
+ begin
248
+ options["order"].each do |param|
249
+ case param
250
+ when :unit
251
+ output << unit
252
+ when :number
253
+ parts = number_with_precision(number, precision).split('.')
254
+ output << number_with_delimiter(parts[0], delimiter) + separator + parts[1].to_s
255
+ end
256
+ end
257
+ rescue
258
+ output = number
259
+ end
260
+ output
261
+ end
262
+ end
263
+ end
264
+ end
265
+
266
+ class Array
267
+ alias :orig_to_sentence :to_sentence
268
+
269
+ # def to_sentence(options = {})
270
+ # options.assert_valid_keys(:connector, :skip_last_comma)
271
+ # options.reverse_merge! :connector => 'and', :skip_last_comma => false
272
+ # options[:connector] = "#{options[:connector]} " unless options[:connector].nil? || options[:connector].strip == ''
273
+ #
274
+ # case length
275
+ # when 0
276
+ # ""
277
+ # when 1
278
+ # self[0].to_s
279
+ # when 2
280
+ # "#{self[0]} #{options[:connector]}#{self[1]}"
281
+ # else
282
+ # "#{self[0...-1].join(', ')}#{options[:skip_last_comma] ? '' : ','} #{options[:connector]}#{self[-1]}"
283
+ # end
284
+ # end
285
+
286
+ def to_sentence(options = {})
287
+ options.reverse_merge!(GermanL10n::ArrayHelper::ToSentenceTexts)
288
+ orig_to_sentence(options)
289
+ end
290
+ end
291
+
292
+ class Date
293
+ # FIXME as these are defined as Ruby constants, they can not be overwritten
294
+ MONTHNAMES = GermanL10n::DateHelper::Monthnames
295
+ ABBR_MONTHNAMES = GermanL10n::DateHelper::AbbrMonthnames
296
+ DAYNAMES = GermanL10n::DateHelper::Daynames
297
+ ABBR_DAYNAMES = GermanL10n::DateHelper::AbbrDaynames
298
+ end
299
+
300
+ class Time
301
+ alias_method :old_strftime, :strftime
302
+
303
+ def strftime(date)
304
+ tmpdate = date.dup
305
+ GermanL10n::localize_strftime(tmpdate, self)
306
+ old_strftime(tmpdate)
307
+ end
308
+ end
309
+
310
+ ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(GermanL10n::DateHelper::DateFormats)
311
+ ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(GermanL10n::DateHelper::TimeFormats)
312
+
313
+ module ActionView
314
+ module Helpers
315
+ module DateHelper
316
+ alias_method :old_distance_of_time_in_words, :distance_of_time_in_words
317
+
318
+ # def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false)
319
+ # from_time = from_time.to_time if from_time.respond_to?(:to_time)
320
+ # to_time = to_time.to_time if to_time.respond_to?(:to_time)
321
+ # distance_in_minutes = (((to_time - from_time).abs)/60).round
322
+ # distance_in_seconds = ((to_time - from_time).abs).round
323
+ #
324
+ # case distance_in_minutes
325
+ # when 0..1
326
+ # return (distance_in_minutes == 0) ? 'less than a minute' : '1 minute' unless include_seconds
327
+ # case distance_in_seconds
328
+ # when 0..4 then 'less than 5 seconds'
329
+ # when 5..9 then 'less than 10 seconds'
330
+ # when 10..19 then 'less than 20 seconds'
331
+ # when 20..39 then 'half a minute'
332
+ # when 40..59 then 'less than a minute'
333
+ # else '1 minute'
334
+ # end
335
+ #
336
+ # when 2..44 then "#{distance_in_minutes} minutes"
337
+ # when 45..89 then 'about 1 hour'
338
+ # when 90..1439 then "about #{(distance_in_minutes.to_f / 60.0).round} hours"
339
+ # when 1440..2879 then '1 day'
340
+ # when 2880..43199 then "#{(distance_in_minutes / 1440).round} days"
341
+ # when 43200..86399 then 'about 1 month'
342
+ # when 86400..525599 then "#{(distance_in_minutes / 43200).round} months"
343
+ # when 525600..1051199 then 'about 1 year'
344
+ # else "over #{(distance_in_minutes / 525600).round} years"
345
+ # end
346
+ # end
347
+
348
+ def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false)
349
+ from_time = from_time.to_time if from_time.respond_to?(:to_time)
350
+ to_time = to_time.to_time if to_time.respond_to?(:to_time)
351
+ distance_in_minutes = (((to_time - from_time).abs)/60).round
352
+ distance_in_seconds = ((to_time - from_time).abs).round
353
+
354
+ messages = GermanL10n::DateHelper::Texts
355
+ case distance_in_minutes
356
+ when 0..1
357
+ return distance_in_minutes == 0 ? messages[:less_than_a_minute] : messages[:one_minute] unless include_seconds
358
+ case distance_in_seconds
359
+ when 0..5 then format( messages[:less_than_x_seconds], 5 )
360
+ when 6..10 then format( messages[:less_than_x_seconds], 10 )
361
+ when 11..20 then format( messages[:less_than_x_seconds], 20 )
362
+ when 21..40 then messages[:half_a_minute]
363
+ when 41..59 then messages[:less_than_a_minute]
364
+ else messages[:one_minute]
365
+ end
366
+ when 2..44 then format(messages[:x_minutes], distance_in_minutes)
367
+ when 45..89 then messages[:one_hour]
368
+ when 90..1439 then format( messages[:x_hours], (distance_in_minutes.to_f / 60.0).round )
369
+ when 1440..2879 then messages[:one_day]
370
+ when 2880..43199 then format( messages[:x_days], (distance_in_minutes / 1440).round )
371
+ when 43200..86399 then messages[:one_month]
372
+ when 86400..525959 then format( messages[:x_months], (distance_in_minutes / 43200).round )
373
+ when 525960..1051919 then messages[:one_year]
374
+ else format( messages[:x_years], (distance_in_minutes / 525960).round )
375
+ end
376
+ end
377
+
378
+ alias_method :orig_date_select, :date_select
379
+
380
+ # def date_select(object_name, method, options = {}, html_options = {})
381
+ # InstanceTag.new(object_name, method, self, nil, options.delete(:object)).to_date_select_tag(options, html_options)
382
+ # end
383
+
384
+ def date_select(object_name, method, options = {}, html_options = {})
385
+ options.reverse_merge!(GermanL10n::DateHelper::DateSelectOrder)
386
+ orig_date_select(object_name, method, options, html_options)
387
+ end
388
+
389
+ alias_method :orig_datetime_select, :datetime_select
390
+
391
+ # def datetime_select(object_name, method, options = {}, html_options = {})
392
+ # InstanceTag.new(object_name, method, self, nil, options.delete(:object)).to_datetime_select_tag(options, html_options)
393
+ # end
394
+
395
+ def datetime_select(object_name, method, options = {}, html_options = {})
396
+ options.reverse_merge!(GermanL10n::DateHelper::DateSelectOrder)
397
+ orig_datetime_select(object_name, method, options, html_options)
398
+ end
399
+ end
400
+ end
401
+ end
@@ -0,0 +1,54 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
2
+
3
+ require 'action_controller/test_process'
4
+ require 'action_view/test_case'
5
+
6
+ class ActionViewTest < Test::Unit::TestCase
7
+ include ActionView::Helpers::DateHelper
8
+ include ActionView::Helpers::NumberHelper
9
+
10
+ def test_class_loads
11
+ assert_nothing_raised { GermanL10n }
12
+ end
13
+
14
+ # def test_date_select_helper
15
+ # result = date_select :record, :method
16
+ # # assert_select 'input#record_method_3i', :count => 1
17
+ # # assert_select 'input#record_method_3i option', :count => 31
18
+ # # assert_select 'input#record_method_2i', :count => 1
19
+ # # assert_select 'input#record_method_3i option', :count => 12
20
+ # # assert_select 'input#record_method_3i', :count => 1
21
+ # end
22
+
23
+ # def test_datetime_select_helper
24
+ # result = datetime_select :record, :method
25
+ # end
26
+
27
+ def test_distance_of_time_in_words
28
+ assert_equal "weniger als eine Minute", distance_of_time_in_words(Time.now, Time.now + 5.seconds)
29
+ assert_equal "weniger als 5 Sekunden", distance_of_time_in_words(Time.now, Time.now + 5.seconds, true)
30
+ assert_equal "weniger als eine Minute", distance_of_time_in_words(Time.now, Time.now + 10.seconds)
31
+ assert_equal "weniger als 10 Sekunden", distance_of_time_in_words(Time.now, Time.now + 10.seconds, true)
32
+ assert_equal "weniger als eine Minute", distance_of_time_in_words(Time.now, Time.now + 20.seconds)
33
+ assert_equal "weniger als 20 Sekunden", distance_of_time_in_words(Time.now, Time.now + 20.seconds, true)
34
+ assert_equal "eine Minute", distance_of_time_in_words(Time.now, Time.now + 40.seconds)
35
+ assert_equal "eine halbe Minute", distance_of_time_in_words(Time.now, Time.now + 40.seconds, true)
36
+ assert_equal "weniger als eine Minute", distance_of_time_in_words(Time.now, Time.now + 59.seconds, true)
37
+ assert_equal "eine Minute", distance_of_time_in_words(Time.now, Time.now + 1.minute)
38
+ assert_equal "44 Minuten", distance_of_time_in_words(Time.now, Time.now + 44.minutes)
39
+ assert_equal "ungefähr eine Stunde", distance_of_time_in_words(Time.now, Time.now + 89.minutes)
40
+ assert_equal "ungefähr 24 Stunden", distance_of_time_in_words(Time.now, Time.now + 1439.minutes)
41
+ assert_equal "ein Tag", distance_of_time_in_words(Time.now, Time.now + 1.day)
42
+ assert_equal "2 Tage", distance_of_time_in_words(Time.now, Time.now + 2.days)
43
+ assert_equal "ein Monat", distance_of_time_in_words(Time.now, Time.now + 1.month)
44
+ assert_equal "2 Monate", distance_of_time_in_words(Time.now, Time.now + 2.months)
45
+ assert_equal "ein Jahr", distance_of_time_in_words(Time.now, Time.now + 1.year + 10.days) # + 10.days for leap years
46
+ assert_equal "2 Jahre", distance_of_time_in_words(Time.now, Time.now + 2.years + 10.days) # + 10.days for leap years
47
+ end
48
+
49
+ def test_number_to_currency
50
+ assert_equal "€100,00", number_to_currency(100.00)
51
+ assert_equal "€1.234,56", number_to_currency(1234.56)
52
+ assert_equal "€1.234,57", number_to_currency(1234.567)
53
+ end
54
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
2
+
3
+ class ActiveRecordTest < Test::Unit::TestCase
4
+ include ActionView::Helpers::ActiveRecordHelper
5
+
6
+ def test_class_loads
7
+ assert_nothing_raised { GermanL10n }
8
+ end
9
+ end
@@ -0,0 +1,90 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
2
+
3
+ class BasicTest < Test::Unit::TestCase
4
+ def test_class_loads
5
+ assert_nothing_raised { GermanL10n }
6
+ end
7
+
8
+ def test_to_sentence
9
+ assert_equal "A und B", %w{A B}.to_sentence
10
+ assert_equal "A, B und C", %w{A B C}.to_sentence
11
+ assert_equal "A, B, C und D", %w{A B C D}.to_sentence
12
+ end
13
+
14
+ def test_inflector
15
+ assert_equal "fehler", "fehler".pluralize
16
+ end
17
+
18
+ def test_date_abbr_month_translations
19
+ assert_equal "Jan", Date.new(2008, 1, 1).strftime("%b")
20
+ assert_equal "Feb", Date.new(2008, 2, 1).strftime("%b")
21
+ assert_equal "Mrz", Date.new(2008, 3, 1).strftime("%b")
22
+ assert_equal "Apr", Date.new(2008, 4, 1).strftime("%b")
23
+ assert_equal "Mai", Date.new(2008, 5, 1).strftime("%b")
24
+ assert_equal "Jun", Date.new(2008, 6, 1).strftime("%b")
25
+ assert_equal "Jul", Date.new(2008, 7, 1).strftime("%b")
26
+ assert_equal "Aug", Date.new(2008, 8, 1).strftime("%b")
27
+ assert_equal "Sep", Date.new(2008, 9, 1).strftime("%b")
28
+ assert_equal "Okt", Date.new(2008, 10, 1).strftime("%b")
29
+ assert_equal "Nov", Date.new(2008, 11, 1).strftime("%b")
30
+ assert_equal "Dez", Date.new(2008, 12, 1).strftime("%b")
31
+ end
32
+
33
+ def test_date_months
34
+ assert_equal "Januar", Date.new(2008, 1, 1).strftime("%B")
35
+ assert_equal "Februar", Date.new(2008, 2, 1).strftime("%B")
36
+ assert_equal "März", Date.new(2008, 3, 1).strftime("%B")
37
+ assert_equal "April", Date.new(2008, 4, 1).strftime("%B")
38
+ assert_equal "Mai", Date.new(2008, 5, 1).strftime("%B")
39
+ assert_equal "Juni", Date.new(2008, 6, 1).strftime("%B")
40
+ assert_equal "Juli", Date.new(2008, 7, 1).strftime("%B")
41
+ assert_equal "August", Date.new(2008, 8, 1).strftime("%B")
42
+ assert_equal "September", Date.new(2008, 9, 1).strftime("%B")
43
+ assert_equal "Oktober", Date.new(2008, 10, 1).strftime("%B")
44
+ assert_equal "November", Date.new(2008, 11, 1).strftime("%B")
45
+ assert_equal "Dezember", Date.new(2008, 12, 1).strftime("%B")
46
+ end
47
+
48
+ def test_date_abbr_day_translations
49
+ assert_equal "Mo", Date.new(2008, 9, 8).strftime("%a")
50
+ assert_equal "Di", Date.new(2008, 9, 9).strftime("%a")
51
+ assert_equal "Mi", Date.new(2008, 9, 10).strftime("%a")
52
+ assert_equal "Do", Date.new(2008, 9, 11).strftime("%a")
53
+ assert_equal "Fr", Date.new(2008, 9, 12).strftime("%a")
54
+ assert_equal "Sa", Date.new(2008, 9, 13).strftime("%a")
55
+ assert_equal "So", Date.new(2008, 9, 14).strftime("%a")
56
+ end
57
+
58
+ def test_date_day_translations
59
+ assert_equal "Montag", Date.new(2008, 9, 8).strftime("%A")
60
+ assert_equal "Dienstag", Date.new(2008, 9, 9).strftime("%A")
61
+ assert_equal "Mittwoch", Date.new(2008, 9, 10).strftime("%A")
62
+ assert_equal "Donnerstag", Date.new(2008, 9, 11).strftime("%A")
63
+ assert_equal "Freitag", Date.new(2008, 9, 12).strftime("%A")
64
+ assert_equal "Samstag", Date.new(2008, 9, 13).strftime("%A")
65
+ assert_equal "Sonntag", Date.new(2008, 9, 14).strftime("%A")
66
+ end
67
+
68
+ def test_date_formats
69
+ date = Date.new(2008, 9, 8)
70
+ assert_equal " 8. 09. 2008", date.to_s(:default)
71
+ assert_equal " 8. Sep.", date.to_s(:short)
72
+ assert_equal "2008-09-08", date.to_s(:db)
73
+ assert_equal "20080908", date.to_s(:number)
74
+ assert_equal "Montag, 8. September 2008", date.to_s(:long)
75
+ assert_equal "Montag, 8. September 2008", date.to_s(:long_ordinal)
76
+ assert_equal " 8 Sep 2008", date.to_s(:rfc822)
77
+ end
78
+
79
+ def test_datetime_formats
80
+ datetime = DateTime.new(2008, 9, 8, 5, 6, 4, "CET")
81
+ assert_equal "Montag, 8. September 2008 05:06 +01:00", datetime.to_s(:default)
82
+ assert_equal "2008-09-08 05:06:04", datetime.to_s(:db)
83
+ assert_equal "20080908050604", datetime.to_s(:number)
84
+ assert_equal "05:06", datetime.to_s(:time)
85
+ assert_equal " 8. Sep. 05:06", datetime.to_s(:short)
86
+ assert_equal "Montag, 8. September 2008, 05:06", datetime.to_s(:long)
87
+ assert_equal "Montag, 8. September 2008, 05:06", datetime.to_s(:long_ordinal)
88
+ assert_equal "Mo, 08 Sep 2008 05:06:04 +0100", datetime.to_s(:rfc822)
89
+ end
90
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ gem 'activesupport', '>= 2.1.1'
5
+ require 'active_support'
6
+
7
+ gem 'activerecord', '>= 2.1.1'
8
+ require 'active_record'
9
+
10
+ gem 'actionpack', '>= 2.1.1'
11
+ require 'action_controller'
12
+
13
+ plugin_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
14
+ require File.join(plugin_root, 'lib/german_l10n')
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cs-german_l10n
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Christoph Schiessl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-09-15 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.1.1
23
+ version:
24
+ description:
25
+ email: c.schiessl@gmx.net
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - init.rb
34
+ - lib
35
+ - lib/german_l10n.rb
36
+ - MIT-LICENCE
37
+ - Rakefile
38
+ - TODO
39
+ - test
40
+ has_rdoc: false
41
+ homepage: http://github.com/cs/german_l10n
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.2.0
63
+ signing_key:
64
+ specification_version: 2
65
+ summary: Easy german localization for Ruby on Rails (>= 2.1.1).
66
+ test_files:
67
+ - test/test_helper.rb
68
+ - test/basic_test.rb
69
+ - test/action_view_test.rb
70
+ - test/active_record_test.rb