stamp-i18n 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
1
  ## v0.0.1
2
2
 
3
3
  * initial release
4
+
5
+ ## v0.1.0
6
+
7
+ * added optional variable to localize_stamp method called 'options'
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
 
23
23
  ## Before using
24
24
 
25
- This gem uses i18n translation mechnism, which means before using it, first we need to add proper translation files to locales folder and then setup i18n configuration. Example YML file used for testing is written in polish - it is located in locale/pl.yml. Look for more examples here: [https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale](https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale)
25
+ This gem uses i18n translation mechnism, which means before using it, first we need to add proper translation files to locales folder and then setup i18n configuration. Example YML files used for testing is written in few various languages and are located in ./locale folder. Look for more examples here: [https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale](https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale)
26
26
 
27
27
  ## Usage
28
28
 
@@ -34,11 +34,18 @@ Same as in [http://rubydoc.info/gems/stamp](http://rubydoc.info/gems/stamp) but
34
34
  we are using new method 'localize_stamp' like this:
35
35
 
36
36
  date = Date.new(2011, 6, 9)
37
- date.localize_stamp("March 1, 1999") #=> "junio 9, 2011" if locale is :de
38
- date.localize_stamp("March 1, 1999") #=> "czerwiec 9, 2011" if locale is :pl
37
+ date.localize_stamp("March 1, 1999") #=> "junio 9, 2011" if default locale is :de
38
+ date.localize_stamp("March 1, 1999") #=> "czerwiec 9, 2011" if default locale is :pl
39
39
 
40
40
  Note that we are still using english names in examples passed to stamp methods.
41
41
 
42
+ You can also optionally pass options (as hash) to new method that will eventually be passed to underling 'I18n.translate' (therefore lookup this methods options for complete reference). For example if you want to use other locale than your default you can use:
43
+
44
+ date = Date.new(2011, 6, 9)
45
+ date.localize_stamp("March 1, 1999", :locale => 'en') #=> "June 9, 2011"
46
+ date.localize_stamp("March 1, 1999", :locale => 'de') #=> "Juni 9, 2011"
47
+ date.localize_stamp("March 1, 1999", :locale => 'pl') #=> "Czerwiec 9, 2011"
48
+
42
49
  ## Contributing
43
50
 
44
51
  1. Fork it
data/lib/stamp-i18n.rb CHANGED
@@ -8,8 +8,8 @@ require "stamp-i18n/version"
8
8
  require 'stamp'
9
9
 
10
10
  module StampI18n
11
- def localize_stamp(example)
12
- I18n.localize self, :format => strftime_format(example)
11
+ def localize_stamp(example, options={})
12
+ I18n.localize self, options.merge({:format => strftime_format(example)})
13
13
  end
14
14
  alias :l_stamp :localize_stamp
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module StampI18n
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
data/locale/de.yml ADDED
@@ -0,0 +1,97 @@
1
+ de:
2
+ date:
3
+ abbr_day_names:
4
+ - So
5
+ - Mo
6
+ - Di
7
+ - Mi
8
+ - Do
9
+ - Fr
10
+ - Sa
11
+ abbr_month_names:
12
+ -
13
+ - Jan
14
+ - Feb
15
+ - Mär
16
+ - Apr
17
+ - Mai
18
+ - Jun
19
+ - Jul
20
+ - Aug
21
+ - Sep
22
+ - Okt
23
+ - Nov
24
+ - Dez
25
+ day_names:
26
+ - Sonntag
27
+ - Montag
28
+ - Dienstag
29
+ - Mittwoch
30
+ - Donnerstag
31
+ - Freitag
32
+ - Samstag
33
+ formats:
34
+ default: ! '%d.%m.%Y'
35
+ long: ! '%e. %B %Y'
36
+ short: ! '%e. %b'
37
+ month_names:
38
+ -
39
+ - Januar
40
+ - Februar
41
+ - März
42
+ - April
43
+ - Mai
44
+ - Juni
45
+ - Juli
46
+ - August
47
+ - September
48
+ - Oktober
49
+ - November
50
+ - Dezember
51
+ order:
52
+ - :day
53
+ - :month
54
+ - :year
55
+ datetime:
56
+ distance_in_words:
57
+ about_x_hours:
58
+ one: etwa eine Stunde
59
+ other: etwa %{count} Stunden
60
+ about_x_months:
61
+ one: etwa ein Monat
62
+ other: etwa %{count} Monate
63
+ about_x_years:
64
+ one: etwa ein Jahr
65
+ other: etwa %{count} Jahre
66
+ almost_x_years:
67
+ one: fast ein Jahr
68
+ other: fast %{count} Jahre
69
+ half_a_minute: eine halbe Minute
70
+ less_than_x_minutes:
71
+ one: weniger als eine Minute
72
+ other: weniger als %{count} Minuten
73
+ less_than_x_seconds:
74
+ one: weniger als eine Sekunde
75
+ other: weniger als %{count} Sekunden
76
+ over_x_years:
77
+ one: mehr als ein Jahr
78
+ other: mehr als %{count} Jahre
79
+ x_days:
80
+ one: ein Tag
81
+ other: ! '%{count} Tage'
82
+ x_minutes:
83
+ one: eine Minute
84
+ other: ! '%{count} Minuten'
85
+ x_months:
86
+ one: ein Monat
87
+ other: ! '%{count} Monate'
88
+ x_seconds:
89
+ one: eine Sekunde
90
+ other: ! '%{count} Sekunden'
91
+ prompts:
92
+ day: Tag
93
+ hour: Stunden
94
+ minute: Minuten
95
+ month: Monat
96
+ second: Sekunden
97
+ year: Jahr
data/locale/en.yml ADDED
@@ -0,0 +1,97 @@
1
+ en:
2
+ date:
3
+ abbr_day_names:
4
+ - Sun
5
+ - Mon
6
+ - Tue
7
+ - Wed
8
+ - Thu
9
+ - Fri
10
+ - Sat
11
+ abbr_month_names:
12
+ -
13
+ - Jan
14
+ - Feb
15
+ - Mar
16
+ - Apr
17
+ - May
18
+ - Jun
19
+ - Jul
20
+ - Aug
21
+ - Sep
22
+ - Oct
23
+ - Nov
24
+ - Dec
25
+ day_names:
26
+ - Sunday
27
+ - Monday
28
+ - Tuesday
29
+ - Wednesday
30
+ - Thursday
31
+ - Friday
32
+ - Saturday
33
+ formats:
34
+ default: ! '%Y-%m-%d'
35
+ long: ! '%B %d, %Y'
36
+ short: ! '%b %d'
37
+ month_names:
38
+ -
39
+ - January
40
+ - February
41
+ - March
42
+ - April
43
+ - May
44
+ - June
45
+ - July
46
+ - August
47
+ - September
48
+ - October
49
+ - November
50
+ - December
51
+ order:
52
+ - :year
53
+ - :month
54
+ - :day
55
+ datetime:
56
+ distance_in_words:
57
+ about_x_hours:
58
+ one: about 1 hour
59
+ other: about %{count} hours
60
+ about_x_months:
61
+ one: about 1 month
62
+ other: about %{count} months
63
+ about_x_years:
64
+ one: about 1 year
65
+ other: about %{count} years
66
+ almost_x_years:
67
+ one: almost 1 year
68
+ other: almost %{count} years
69
+ half_a_minute: half a minute
70
+ less_than_x_minutes:
71
+ one: less than a minute
72
+ other: less than %{count} minutes
73
+ less_than_x_seconds:
74
+ one: less than 1 second
75
+ other: less than %{count} seconds
76
+ over_x_years:
77
+ one: over 1 year
78
+ other: over %{count} years
79
+ x_days:
80
+ one: 1 day
81
+ other: ! '%{count} days'
82
+ x_minutes:
83
+ one: 1 minute
84
+ other: ! '%{count} minutes'
85
+ x_months:
86
+ one: 1 month
87
+ other: ! '%{count} months'
88
+ x_seconds:
89
+ one: 1 second
90
+ other: ! '%{count} seconds'
91
+ prompts:
92
+ day: Day
93
+ hour: Hour
94
+ minute: Minute
95
+ month: Month
96
+ second: Seconds
97
+ year: Year
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'stamp-i18n'
2
2
 
3
3
  I18n.load_path << 'locale/pl.yml'
4
+ I18n.load_path << 'locale/en.yml'
5
+ I18n.load_path << 'locale/de.yml'
4
6
  I18n.default_locale='pl'
@@ -2,25 +2,32 @@ require 'spec_helper'
2
2
 
3
3
  describe StampI18n do
4
4
 
5
+ before :each do
6
+ @date = Date.new(2011, 6, 9)
7
+ end
8
+
5
9
  it 'should use old stamp method' do
6
- date = Date.new(2011, 6, 9)
7
- date.stamp("March 1, 1999").should == "June 9, 2011"
8
- date.stamp("Jan 1, 1999").should == "Jun 9, 2011"
9
- date.stamp("Jan 01").should == "Jun 09"
10
- date.stamp("Sunday, May 1, 2000").should == "Thursday, June 9, 2011"
11
- date.stamp("Sun Aug 5").should == "Thu Jun 9"
12
- date.stamp("12/31/99").should == "06/09/11"
13
- date.stamp("DOB: 12/31/2000").should == "DOB: 06/09/2011"
10
+ @date.stamp("March 1, 1999").should == "June 9, 2011"
11
+ @date.stamp("Jan 1, 1999").should == "Jun 9, 2011"
12
+ @date.stamp("Jan 01").should == "Jun 09"
13
+ @date.stamp("Sunday, May 1, 2000").should == "Thursday, June 9, 2011"
14
+ @date.stamp("Sun Aug 5").should == "Thu Jun 9"
15
+ @date.stamp("12/31/99").should == "06/09/11"
16
+ @date.stamp("DOB: 12/31/2000").should == "DOB: 06/09/2011"
14
17
  end
15
18
 
16
19
  it 'should use new localize stamp method' do
17
- date = Date.new(2011, 6, 9)
18
- date.localize_stamp("March 1, 1999").should == "Czerwiec 9, 2011"
19
- date.localize_stamp("Jan 1, 1999").should == "cze 9, 2011"
20
- date.localize_stamp("Jan 01").should == "cze 09"
21
- date.localize_stamp("Sunday, May 1, 2000").should == "czwartek, Czerwiec 9, 2011"
22
- date.localize_stamp("Sun Aug 5").should == "czw cze 9"
23
- date.localize_stamp("12/31/99").should == "06/09/11"
24
- date.localize_stamp("DOB: 12/31/2000").should == "DOB: 06/09/2011"
20
+ @date.localize_stamp("March 1, 1999").should == "Czerwiec 9, 2011"
21
+ @date.localize_stamp("Jan 1, 1999").should == "cze 9, 2011"
22
+ @date.localize_stamp("Jan 01").should == "cze 09"
23
+ @date.localize_stamp("Sunday, May 1, 2000").should == "czwartek, Czerwiec 9, 2011"
24
+ @date.localize_stamp("Sun Aug 5").should == "czw cze 9"
25
+ @date.localize_stamp("12/31/99").should == "06/09/11"
26
+ @date.localize_stamp("DOB: 12/31/2000").should == "DOB: 06/09/2011"
27
+ end
28
+
29
+ it 'should be able to specify locale option on method call' do
30
+ @date.localize_stamp("March 1, 1999", :locale => 'en').should == "June 9, 2011"
31
+ @date.localize_stamp("March 1, 1999", :locale => 'de').should == "Juni 9, 2011"
25
32
  end
26
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stamp-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-30 00:00:00.000000000 Z
12
+ date: 2012-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -93,6 +93,8 @@ files:
93
93
  - Rakefile
94
94
  - lib/stamp-i18n.rb
95
95
  - lib/stamp-i18n/version.rb
96
+ - locale/de.yml
97
+ - locale/en.yml
96
98
  - locale/pl.yml
97
99
  - spec/spec_helper.rb
98
100
  - spec/stamp/stamp_spec.rb