delocalize 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -105,6 +105,102 @@ You can also customize the output using some options:
105
105
  Since `I18n.localize` supports localizing `strftime` strings, we can also do this:
106
106
  <%= f.text_field :released_on, :format => "%B %Y" %>
107
107
 
108
+ ### Ruby 1.9 + Psych YAML Parser
109
+
110
+ You will need to adjust the localization formatting when using the new YAML parser Psych. Below is an example error message you may receive in your logs as well as an example of acceptable formatting and helpful links for reference:
111
+
112
+ __Error message from logs:__
113
+
114
+ Psych::SyntaxError (couldn't parse YAML at line x column y):
115
+
116
+ __References:__
117
+
118
+ The solution can be found here: http://stackoverflow.com/questions/4980877/rails-error-couldnt-parse-yaml#answer-5323060
119
+
120
+ http://pivotallabs.com/users/mkocher/blog/articles/1692-yaml-psych-and-ruby-1-9-2-p180-here-there-be-dragons
121
+
122
+ __Psych Preferred Formatting:__
123
+
124
+ en:
125
+ number:
126
+ format:
127
+ separator: '.'
128
+ delimiter: ','
129
+ precision: 2
130
+ date:
131
+ input:
132
+ formats:
133
+ - :default
134
+ - :long
135
+ - :short
136
+ formats:
137
+ default: "%m/%d/%Y"
138
+ short: "%b %e"
139
+ long: "%B %e, %Y"
140
+ only_day: "%e"
141
+ day_names:
142
+ - Sunday
143
+ - Monday
144
+ - Tuesday
145
+ - Wednesday
146
+ - Thursday
147
+ - Friday
148
+ - Saturday
149
+ abbr_day_names:
150
+ - Sun
151
+ - Mon
152
+ - Tue
153
+ - Wed
154
+ - Thur
155
+ - Fri
156
+ - Sat
157
+ month_names:
158
+ - ~
159
+ - January
160
+ - February
161
+ - March
162
+ - April
163
+ - May
164
+ - June
165
+ - July
166
+ - August
167
+ - September
168
+ - October
169
+ - November
170
+ - December
171
+ abbr_month_names:
172
+ - ~
173
+ - Jan
174
+ - Feb
175
+ - Mar
176
+ - Apr
177
+ - May
178
+ - Jun
179
+ - Jul
180
+ - Aug
181
+ - Sep
182
+ - Oct
183
+ - Nov
184
+ - Dec
185
+ order:
186
+ - :month
187
+ - :day
188
+ - :year
189
+ time:
190
+ input:
191
+ formats:
192
+ - :default
193
+ - :long
194
+ - :short
195
+ - :time
196
+ formats:
197
+ default: "%m/%d/%Y %I:%M%p"
198
+ short: "%B %e %I:%M %p"
199
+ long: "%A, %B %e, %Y %I:%M%p"
200
+ time: "%l:%M%p"
201
+ am: "am"
202
+ pm: "pm"
203
+
108
204
  ### Compatibility
109
205
 
110
206
  * Tested with Rails 2.3.5 in Ruby 1.8.7, Ruby 1.9.1 and Ruby 1.9.2 (head)
@@ -115,10 +211,14 @@ You can also customize the output using some options:
115
211
  People who have contributed to delocalize (in no particular order):
116
212
 
117
213
  * [Fernando Luizao](http://github.com/fernandoluizao)
118
- * [Stephan](http://github.com/stepahn)
214
+ * [Stephan Zalewski](http://github.com/stepahn)
119
215
  * [Lailson Bandeira](http://github.com/lailsonbm)
120
216
  * [Carlos Antonio da Silva](http://github.com/carlosantoniodasilva)
121
217
  * [Michele Franzin](http://github.com/michelefranzin)
218
+ * [Raphaela Wrede](https://github.com/rwrede)
219
+ * [Jan De Poorter](https://github.com/DefV)
220
+ * [Blake Lucchesi](https://github.com/BlakeLucchesi)
221
+ * [Ralph von der Heyden](https://github.com/ralph)
122
222
 
123
223
  ### TODO
124
224
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -61,7 +61,7 @@ module Delocalize
61
61
  def input_formats(type)
62
62
  # Date uses date formats, all others use time formats
63
63
  type = type == Date ? :date : :time
64
- (@input_formats ||= {})[type] ||= I18n.t(:"#{type}.formats").slice(*I18n.t(:"#{type}.input.formats")).values
64
+ I18n.t(:"#{type}.formats").slice(*I18n.t(:"#{type}.input.formats")).values
65
65
  end
66
66
 
67
67
  def apply_regex(format)
@@ -29,6 +29,19 @@ class DelocalizeActiveRecordTest < ActiveRecord::TestCase
29
29
  assert_equal date, @product.released_on
30
30
  end
31
31
 
32
+ test "delocalizes localized date with year even if locale changes" do
33
+ date = Date.civil(2009, 10, 19)
34
+
35
+ @product.released_on = '19. Oktober 2009'
36
+ assert_equal date, @product.released_on
37
+
38
+ I18n.with_locale :tt do
39
+ @product.released_on = '10|11|2009'
40
+ date = Date.civil(2009, 11, 10)
41
+ assert_equal date, @product.released_on
42
+ end
43
+ end
44
+
32
45
  test "delocalizes localized date without year" do
33
46
  date = Date.civil(Date.today.year, 10, 19)
34
47
 
@@ -11,7 +11,7 @@ require 'delocalize/rails_ext/action_view'
11
11
  require 'delocalize/rails_ext/active_record'
12
12
  require 'delocalize/rails_ext/time_zone'
13
13
 
14
- I18n.backend.store_translations :de, {
14
+ de = {
15
15
  :date => {
16
16
  :input => {
17
17
  :formats => [:long, :short, :default]
@@ -50,6 +50,13 @@ I18n.backend.store_translations :de, {
50
50
  }
51
51
  }
52
52
 
53
+ # deeply clone the hash for a fantasy language called tt
54
+ tt = Marshal.load(Marshal.dump(de))
55
+ tt[:date][:formats][:default] = '%d|%m|%Y'
56
+
57
+ I18n.backend.store_translations :de, de
58
+ I18n.backend.store_translations :tt, tt
59
+
53
60
  I18n.locale = :de
54
61
 
55
62
  class NonArProduct
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delocalize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-25 00:00:00.000000000Z
12
+ date: 2011-11-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2156597040 !ruby/object:Gem::Requirement
16
+ requirement: &2160177200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156597040
24
+ version_requirements: *2160177200
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &2156596420 !ruby/object:Gem::Requirement
27
+ requirement: &2160175980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.3.4
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2156596420
35
+ version_requirements: *2160175980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: timecop
38
- requirement: &2156595740 !ruby/object:Gem::Requirement
38
+ requirement: &2160174480 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 0.3.5
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2156595740
46
+ version_requirements: *2160174480
47
47
  description: Delocalize is a tool for parsing localized dates/times and numbers.
48
48
  email: clemens@railway.at
49
49
  executables: []