parsi-localize 0.2.1 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/Gemfile.lock +23 -0
- data/README.markdown +18 -31
- data/lib/parsi-localize.rb +32 -0
- data/lib/version.rb +3 -3
- data/locale/fa.yml +4 -4
- data/parsi-localize.gemspec +5 -5
- data/test/parsi_localize_test.rb +1 -1
- data/test/test_helper.rb +1 -2
- metadata +11 -11
- data/init.rb +0 -1
- data/lib/parsi_localize.rb +0 -30
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
|
-
|
5
|
-
This gem contains two sections
|
4
|
+
Enhance I18n localize to use Parsi digits and Jalaly dates in Farsi (فارسی) locale.
|
6
5
|
|
7
|
-
|
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 '
|
12
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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 %
|
47
|
-
long: "%A، %e %
|
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 %
|
52
|
-
long: "%A، %e %
|
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
|
-
=> "یکشنبه، ۱۶ بهمن ۱۳۹۰، ساعت ۱۵:۴۳:۳۰
|
57
|
+
=> "یکشنبه، ۱۶ بهمن ۱۳۹۰، ساعت ۱۵:۴۳:۳۰"
|
71
58
|
|
72
|
-
For more info on
|
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
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 %
|
6
|
-
long: "%A، %e %
|
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 %
|
13
|
-
long: "%A، %e %
|
12
|
+
short: "%d %B"
|
13
|
+
long: "%A، %e %B %Y"
|
data/parsi-localize.gemspec
CHANGED
@@ -5,13 +5,13 @@ Gem::Specification.new do |s|
|
|
5
5
|
|
6
6
|
# Description Meta...
|
7
7
|
s.name = 'parsi-localize'
|
8
|
-
s.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 = '
|
14
|
-
s.description = '
|
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("
|
28
|
+
s.add_dependency("parsi-digits", ">= 0.3")
|
29
|
+
s.add_dependency("parsi-date", ">= 0.2.2")
|
30
30
|
end
|
data/test/parsi_localize_test.rb
CHANGED
@@ -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 "یکشنبه، ۱۶ بهمن ۱۳۹۰، ساعت ۱۵:۴۳:۳۰
|
30
|
+
assert_equal "یکشنبه، ۱۶ بهمن ۱۳۹۰، ساعت ۱۵:۴۳:۳۰", I18n.l(time, format: :long)
|
31
31
|
end
|
32
32
|
end
|
data/test/test_helper.rb
CHANGED
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.
|
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-
|
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:
|
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:
|
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:
|
94
|
-
description:
|
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
|
-
-
|
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:
|
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'
|
data/lib/parsi_localize.rb
DELETED
@@ -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
|