parsi-localize 0.2.1 → 0.3

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/.gitignore CHANGED
@@ -1,5 +1,4 @@
1
1
  *.gem
2
2
  .bundle
3
- Gemfile.lock
4
3
  pkg/*
5
4
 
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ parsi-localize (0.3)
5
+ i18n
6
+ parsi-date (>= 0.2.2)
7
+ parsi-digits (>= 0.3)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ i18n (0.6.1)
13
+ parsi-date (0.2.2)
14
+ parsi-digits (0.3)
15
+ rake (0.9.2.2)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ bundler
22
+ parsi-localize!
23
+ rake
data/README.markdown CHANGED
@@ -1,57 +1,44 @@
1
1
  ParsiLocalize
2
2
  =============
3
3
 
4
- Change I18n localize to use parsi digits and jalaly dates in farsi (فارسی) locale.
5
- This gem contains two sections
4
+ Enhance I18n localize to use Parsi digits and Jalaly dates in Farsi (فارسی) locale.
6
5
 
7
- ParsiDigits
8
- -----------
9
- Simply change digits in a string/integer/float to unicode parsi digits:
6
+ For changing digits in string/integer/float with Unicode Parsi ones, we use
7
+ [`parsi-digits`](https://github.com/hzamani/parsi-digits):
10
8
 
11
- require 'parsi_digits'
12
- "15,000 تومان".with_parsi_digits
13
- => "۱۵,۰۰۰ تومان"
14
- 123.25.with_parsi_digits
15
- => "۱۲۳/۲۵"
16
-
17
- It also dose the reverse action:
18
-
19
- "۱۲۳۴۵".with_western_digits
20
- => "12345"
9
+ require 'parsi-localize'
10
+ I18n.l ‪‪"15,000 تومان"
11
+ => ‫‫"۱۵,۰۰۰ تومان"
21
12
 
22
- And it undersanad parsi digits (which is useful especially for input forms):
13
+ Another useful feature of `parsi-digits` is that you can parse strings with Unicode
14
+ digits to numerics:
23
15
 
24
16
  "۱۲۳۴۵".to_i
25
17
  => 12345
26
18
  "۱۹/۸".to_f
27
19
  => 19.8
28
20
 
29
- ParsiLocalize
30
- -------------
31
- Change behaivor of I18n#localize so that it localize digits and dates in 'farsi' locale.
21
+ To have a real localization of dates in I18n#localize, we uses [`parsi-date`](https://github.com/hzamani/parsi-date) to convert dates to Jalali.
32
22
 
33
- require 'parsi_localize'
34
- I18n.l ‪‪"15,000 تومان"
35
- => ‫‫"۱۵,۰۰۰ تومان"
36
23
  I18n.l Time.now, fromat: "%y/%m/%d %H:%M:%S"
37
24
  => "۹۰/۱۰/۱۳ ۰۵:۴۳:۳۲"
38
25
 
39
- If you don't set date format, it uses the default locale format, wich you can set in your locale file.
26
+ As you know, date and time formats can be sored in the locale file.
40
27
  For example with
41
28
 
42
29
  fa:
43
30
  time:
44
31
  formats:
45
32
  default: "%y/%m/%d %H:%M:%S"
46
- short: "%d %b، %H:%M"
47
- long: "%A، %e %b %Y، ساعت %H:%M:%S (%Z)"
33
+ short: "%d %B، %H:%M"
34
+ long: "%A، %e %B %Y، ساعت %H:%M:%S"
48
35
  date:
49
36
  formats:
50
37
  default: "%y/%m/%d"
51
- short: "%d %b"
52
- long: "%A، %e %b %Y"
53
-
54
- in your locale file you will get:
38
+ short: "%d %B"
39
+ long: "%A، %e %B %Y"
40
+
41
+ in your locale file, you will get:
55
42
 
56
43
  date = Date.today
57
44
  I18n.l date
@@ -67,8 +54,8 @@ in your locale file you will get:
67
54
  I18n.l time, format: :short
68
55
  => ‫"۱۶ بهمن، ۱۵:۴۳"
69
56
  I18n.l time, format: :long
70
- => ‫"یک‌شنبه، ۱۶ بهمن ۱۳۹۰، ساعت ۱۵:۴۳:۳۰ (IRST)"
57
+ => ‫"یک‌شنبه، ۱۶ بهمن ۱۳۹۰، ساعت ۱۵:۴۳:۳۰"
71
58
 
72
- For more info on dateformating see 'jalalidate' docs
59
+ For more info on date formating see `parsi-date` and Ruby's built-in `date` docs.
73
60
 
74
61
  Copyright (c) 2012 Hassan Zamani, released under the MIT license.
@@ -0,0 +1,32 @@
1
+ require 'parsi-digits'
2
+ require 'parsi-date'
3
+ require 'i18n'
4
+
5
+ module I18n
6
+ class << self
7
+ def localize object, options={}
8
+ return '' if object.nil?
9
+
10
+ locale = options.delete(:locale) || config.locale
11
+ format = options.delete(:format) || :default
12
+
13
+ if [:default, :short, :long].include? format
14
+ format = I18n.t("date.formats.#{format}") if object.is_a? Date
15
+ format = I18n.t("time.formats.#{format}") if object.is_a? Time
16
+ end
17
+
18
+ if locale == :fa
19
+ if object.respond_to?(:with_parsi_digits)
20
+ object.with_parsi_digits
21
+ elsif [Date, DateTime, Time, Parsi::Date, Parsi::DateTime].include? object.class
22
+ object.to_jalali.strftime(format).with_parsi_digits
23
+ else
24
+ config.backend.localize locale, object, format, options
25
+ end
26
+ else
27
+ config.backend.localize locale, object, format, options
28
+ end
29
+ end
30
+ alias :l :localize
31
+ end
32
+ end
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
- module I18n
2
- module ParsiLocalize
3
- VERSION = "0.2.1"
1
+ module Parsi
2
+ module Localize
3
+ VERSION = "0.3"
4
4
  end
5
5
  end
data/locale/fa.yml CHANGED
@@ -2,12 +2,12 @@ fa:
2
2
  time:
3
3
  formats:
4
4
  default: "%y/%m/%d %H:%M:%S"
5
- short: "%d %b، %H:%M"
6
- long: "%A، %e %b %Y، ساعت %H:%M:%S (%Z)"
5
+ short: "%d %B، %H:%M"
6
+ long: "%A، %e %B %Y، ساعت %H:%M:%S"
7
7
  am: "قبل از ظهر"
8
8
  pm: "بعد از ظهر"
9
9
  date:
10
10
  formats:
11
11
  default: "%y/%m/%d"
12
- short: "%d %b"
13
- long: "%A، %e %b %Y"
12
+ short: "%d %B"
13
+ long: "%A، %e %B %Y"
@@ -5,13 +5,13 @@ Gem::Specification.new do |s|
5
5
 
6
6
  # Description Meta...
7
7
  s.name = 'parsi-localize'
8
- s.version = I18n::ParsiLocalize::VERSION
8
+ s.version = Parsi::Localize::VERSION
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.author = 'Hassan Zamani'
11
11
  s.email = 'hsn.zamani@gmail.com'
12
12
  s.homepage = 'http://github.com/hzamani/parsi_localize'
13
- s.summary = 'Change I18n localize to use parsi digits and jalaly dates in farsi locale'
14
- s.description = 'Change I18n localize to use parsi digits and jalaly dates in farsi locale'
13
+ s.summary = 'Enhance I18n#localize to use parsi digits and Jalali dates in Farsi locale'
14
+ s.description = 'Enhance I18n#localize to use parsi digits and Jalali dates in Farsi locale'
15
15
 
16
16
 
17
17
  # Load Paths...
@@ -25,6 +25,6 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency("bundler")
26
26
  s.add_development_dependency("rake")
27
27
  s.add_dependency("i18n")
28
- s.add_dependency("parsi-digits")
29
- s.add_dependency("jalalidate")
28
+ s.add_dependency("parsi-digits", ">= 0.3")
29
+ s.add_dependency("parsi-date", ">= 0.2.2")
30
30
  end
@@ -27,6 +27,6 @@ class ParsiLocalizeTest < Test::Unit::TestCase
27
27
  assert_equal "۹۰/۱۱/۱۶ ۱۵:۴۳:۳۰", I18n.l(time)
28
28
  assert_equal "۹۰/۱۱/۱۶ ۱۵:۴۳:۳۰", I18n.l(time, format: :default)
29
29
  assert_equal "۱۶ بهمن، ۱۵:۴۳", I18n.l(time, format: :short)
30
- assert_equal "یک‌شنبه، ۱۶ بهمن ۱۳۹۰، ساعت ۱۵:۴۳:۳۰ (IRST)", I18n.l(time, format: :long)
30
+ assert_equal "یک‌شنبه، ۱۶ بهمن ۱۳۹۰، ساعت ۱۵:۴۳:۳۰", I18n.l(time, format: :long)
31
31
  end
32
32
  end
data/test/test_helper.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'test/unit'
2
2
  require 'i18n'
3
- require 'parsi_digits'
4
- require 'parsi_localize'
3
+ require 'parsi-localize'
5
4
 
6
5
  I18n.load_path = ['locale/fa.yml']
7
6
  I18n.default_locale = :fa
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.2.1
4
+ version: '0.3'
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-09-13 00:00:00.000000000 Z
12
+ date: 2012-10-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: '0.3'
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,15 +74,15 @@ dependencies:
74
74
  requirements:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
- version: '0'
77
+ version: '0.3'
78
78
  - !ruby/object:Gem::Dependency
79
- name: jalalidate
79
+ name: parsi-date
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
83
  - - ! '>='
84
84
  - !ruby/object:Gem::Version
85
- version: '0'
85
+ version: 0.2.2
86
86
  type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,8 +90,8 @@ dependencies:
90
90
  requirements:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
- version: '0'
94
- description: Change I18n localize to use parsi digits and jalaly dates in farsi locale
93
+ version: 0.2.2
94
+ description: Enhance I18n#localize to use parsi digits and Jalali dates in Farsi locale
95
95
  email: hsn.zamani@gmail.com
96
96
  executables: []
97
97
  extensions: []
@@ -99,10 +99,10 @@ extra_rdoc_files: []
99
99
  files:
100
100
  - .gitignore
101
101
  - Gemfile
102
+ - Gemfile.lock
102
103
  - README.markdown
103
104
  - Rakefile
104
- - init.rb
105
- - lib/parsi_localize.rb
105
+ - lib/parsi-localize.rb
106
106
  - lib/version.rb
107
107
  - locale/en.yml
108
108
  - locale/fa.yml
@@ -132,7 +132,7 @@ rubyforge_project:
132
132
  rubygems_version: 1.8.24
133
133
  signing_key:
134
134
  specification_version: 3
135
- summary: Change I18n localize to use parsi digits and jalaly dates in farsi locale
135
+ summary: Enhance I18n#localize to use parsi digits and Jalali dates in Farsi locale
136
136
  test_files:
137
137
  - test/parsi_localize_test.rb
138
138
  - test/test_helper.rb
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'parsi_localize'
@@ -1,30 +0,0 @@
1
- require 'parsi_digits'
2
- require 'jalalidate'
3
- require 'i18n'
4
-
5
- module I18n
6
- class << self
7
- def localize(object, options={})
8
- return '' if object.nil?
9
-
10
- locale = options.delete(:locale) || config.locale
11
- format = options.delete(:format) || :default
12
-
13
- if locale == :fa and not object.nil?
14
- if object.respond_to? :with_parsi_digits
15
- object.with_parsi_digits
16
- elsif object.is_a? Date or object.is_a? Time
17
- jdate = JalaliDate.new object
18
- if [:default, :short, :long].include? format
19
- format = I18n.t("date.formats.#{format}") if object.is_a? Date
20
- format = I18n.t("time.formats.#{format}") if object.is_a? Time
21
- end
22
- jdate.strftime(format).with_parsi_digits
23
- end
24
- else
25
- config.backend.localize(locale, object, format, options)
26
- end
27
- end
28
- alias :l :localize
29
- end
30
- end