parsi-localize 0.1.1 → 0.1.2

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.markdown CHANGED
@@ -8,12 +8,10 @@ ParsiDigits
8
8
  -----------
9
9
  Simply change digits in a string/integer/float to unicode parsi digits.
10
10
 
11
- (In all the example below we have right to left issues to present output!)
12
-
13
11
  Example:
14
12
 
15
13
  require 'parsi_digits'
16
- ‪"15,000 تومان".with_parsi_digits => "۱۵,۰۰۰ تومان"
14
+ ‪"15,000 تومان".with_parsi_digits => "۱۵,۰۰۰ تومان"
17
15
  123.25.with_parsi_digits => "۱۲۳/۲۵"
18
16
 
19
17
 
@@ -22,19 +20,44 @@ ParsiLocalize
22
20
  Change behaivor of I18n#localize so that it localize digits and dates in 'farsi' locale.
23
21
 
24
22
  require 'parsi_localize'
25
- I18n.l "15,000 تومان" => "۱۵,۰۰۰ تومان"
26
- I18n.l Time.now, fromat: "%y/%m/%d %H:%M:%S" => "۹۰/۱۰/۱۳ ۰۵:۴۳:۳۲"
23
+ I18n.l ‪‪"15,000 تومان"
24
+ => ‫‫"۱۵,۰۰۰ تومان"
25
+ I18n.l Time.now, fromat: "%y/%m/%d %H:%M:%S"
26
+ => "۹۰/۱۰/۱۳ ۰۵:۴۳:۳۲"
27
27
 
28
- If you don't set date format, it uses the default locale format (time.formats.default) wich you can set in your locale file. For more info on dateformating see 'jalalidate' docs
28
+ If you don't set date format, it uses the default locale format, wich you can set in your locale file.
29
29
  For example with
30
30
 
31
31
  fa:
32
32
  time:
33
33
  formats:
34
- default: "%d %b %y"
34
+ default: "%y/%m/%d %H:%M:%S"
35
+ short: "%d %b، %H:%M"
36
+ long: "%A، %e %b %Y، ساعت %H:%M:%S (%Z)"
37
+ date:
38
+ formats:
39
+ default: "%y/%m/%d"
40
+ short: "%d %b"
41
+ long: "%A، %e %b %Y"
35
42
 
36
43
  in your locale file you will get:
37
44
 
38
- I18n.l Time.now => "۱۳ دی ۹۰"
45
+ date = Date.today
46
+ I18n.l date
47
+ => ‫"۹۰/۱۱/۱۶"
48
+ I18n.l date, format: :short
49
+ => ‫"۱۶ بهمن"
50
+ I18n.l date, format: :long
51
+ => ‫"یک‌شنبه، ۱۶ بهمن ۱۳۹۰"
52
+
53
+ time = Time.now
54
+ I18n.l time
55
+ => "۹۰/۱۱/۱۶ ۱۵:۴۳:۳۰"
56
+ I18n.l time, format: :short
57
+ => ‫"۱۶ بهمن، ۱۵:۴۳"
58
+ I18n.l time, format: :long
59
+ => ‫"یک‌شنبه، ۱۶ بهمن ۱۳۹۰، ساعت ۱۵:۴۳:۳۰ (IRST)"
60
+
61
+ For more info on dateformating see 'jalalidate' docs
39
62
 
40
63
  Copyright (c) 2012 Hassan Zamani, released under the MIT license.
@@ -13,7 +13,10 @@ module I18n
13
13
  object.with_parsi_digits
14
14
  elsif object.is_a? Date or object.is_a? Time
15
15
  jdate = JalaliDate.new object
16
- format = I18n.t("time.formats.default") if format == :default
16
+ if [:default, :short, :long].include? format
17
+ format = I18n.t("date.formats.#{format}") if object.is_a? Date
18
+ format = I18n.t("time.formats.#{format}") if object.is_a? Time
19
+ end
17
20
  jdate.strftime(format).with_parsi_digits
18
21
  end
19
22
  else
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module I18n
2
2
  module ParsiLocalize
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
data/locale/fa.yml CHANGED
@@ -6,3 +6,8 @@ fa:
6
6
  long: "%A، %e %b %Y، ساعت %H:%M:%S (%Z)"
7
7
  am: "قبل از ظهر"
8
8
  pm: "بعد از ظهر"
9
+ date:
10
+ formats:
11
+ default: "%y/%m/%d"
12
+ short: "%d %b"
13
+ long: "%A، %e %b %Y"
@@ -15,14 +15,25 @@ class ParsiDigitsTest < Test::Unit::TestCase
15
15
  assert_equal "۹/۰۸۷۶۵۴۳۲۱", 9.087654321.with_parsi_digits
16
16
  end
17
17
 
18
- def test_localize
18
+ def test_localize_numbers
19
19
  assert_equal "۹۸۷۶۵۴۳۲۱۰", I18n.l("9876543210")
20
20
  assert_equal "۹۸۷۶۵۴۳۲۱۰", I18n.l(9876543210)
21
21
  assert_equal "۹/۰۸۷۶۵۴۳۲۱", I18n.l(9.087654321)
22
- time = Time.mktime(2012, 1, 3, 5, 43, 32)
23
- date = Time.mktime(2012, 1, 3)
24
- assert_equal "۹۰/۱۰/۱۳ ۰۵:۴۳:۳۲", I18n.l(time)
25
- assert_equal "۹۰/۱۰/۱۳ ۰۰:۰۰:۰۰", I18n.l(date)
26
- assert_equal "۱۳ دی ۹۰", I18n.l(time, format: "%d %b %y")
22
+ end
23
+
24
+ def test_localize_date_format
25
+ date = Date.new(2012, 2, 5)
26
+ assert_equal "۹۰/۱۱/۱۶", I18n.l(date)
27
+ assert_equal "۹۰/۱۱/۱۶", I18n.l(date, format: :default)
28
+ assert_equal "۱۶ بهمن", I18n.l(date, format: :short)
29
+ assert_equal "یک‌شنبه، ۱۶ بهمن ۱۳۹۰", I18n.l(date, format: :long)
30
+ end
31
+
32
+ def test_localize_time_format
33
+ time = Time.new(2012, 2, 5, 15, 43, 30)
34
+ assert_equal "۹۰/۱۱/۱۶ ۱۵:۴۳:۳۰", I18n.l(time)
35
+ assert_equal "۹۰/۱۱/۱۶ ۱۵:۴۳:۳۰", I18n.l(time, format: :default)
36
+ assert_equal "۱۶ بهمن، ۱۵:۴۳", I18n.l(time, format: :short)
37
+ assert_equal "یک‌شنبه، ۱۶ بهمن ۱۳۹۰، ساعت ۱۵:۴۳:۳۰ (IRST)", I18n.l(time, format: :long)
27
38
  end
28
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parsi-localize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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: 2012-01-02 00:00:00.000000000 Z
12
+ date: 2012-01-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &12989160 !ruby/object:Gem::Requirement
16
+ requirement: &16268080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *12989160
24
+ version_requirements: *16268080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &12988740 !ruby/object:Gem::Requirement
27
+ requirement: &16267660 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *12988740
35
+ version_requirements: *16267660
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: i18n
38
- requirement: &12988060 !ruby/object:Gem::Requirement
38
+ requirement: &16267240 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *12988060
46
+ version_requirements: *16267240
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jalalidate
49
- requirement: &12987420 !ruby/object:Gem::Requirement
49
+ requirement: &16266820 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *12987420
57
+ version_requirements: *16266820
58
58
  description: Change I18n localize to use parsi digits and jalaly dates in farsi locale
59
59
  email: hsn.zamani@gmail.com
60
60
  executables: []