parsi-localize 0.1.3 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.markdown +2 -30
- data/lib/version.rb +1 -1
- data/parsi-localize.gemspec +2 -1
- data/test/parsi_localize_test.rb +2 -2
- metadata +23 -16
- data/init.rb +0 -1
- data/lib/parsi_digits.rb +0 -69
- data/locale/en.yml +0 -0
- data/test/parsi_digits_test.rb +0 -38
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 Hassan Zamani
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
CHANGED
@@ -1,33 +1,6 @@
|
|
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
|
6
|
-
|
7
|
-
ParsiDigits
|
8
|
-
-----------
|
9
|
-
Simply change digits in a string/integer/float to unicode parsi digits:
|
10
|
-
|
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"
|
21
|
-
|
22
|
-
And it undersanad parsi digits (which is useful especially for input forms):
|
23
|
-
|
24
|
-
"۱۲۳۴۵".to_i
|
25
|
-
=> 12345
|
26
|
-
"۱۹/۸".to_f
|
27
|
-
=> 19.8
|
28
|
-
|
29
|
-
ParsiLocalize
|
30
|
-
-------------
|
31
4
|
Change behaivor of I18n#localize so that it localize digits and dates in 'farsi' locale.
|
32
5
|
|
33
6
|
require 'parsi_localize'
|
@@ -36,8 +9,7 @@ Change behaivor of I18n#localize so that it localize digits and dates in 'farsi'
|
|
36
9
|
I18n.l Time.now, fromat: "%y/%m/%d %H:%M:%S"
|
37
10
|
=> "۹۰/۱۰/۱۳ ۰۵:۴۳:۳۲"
|
38
11
|
|
39
|
-
If you don't set date format, it uses the default locale format, wich you can set in your locale file.
|
40
|
-
For example with
|
12
|
+
If you don't set date format, it uses the default locale format, wich you can set in your locale file. For example with
|
41
13
|
|
42
14
|
fa:
|
43
15
|
time:
|
@@ -69,6 +41,6 @@ in your locale file you will get:
|
|
69
41
|
I18n.l time, format: :long
|
70
42
|
=> "یکشنبه، ۱۶ بهمن ۱۳۹۰، ساعت ۱۵:۴۳:۳۰ (IRST)"
|
71
43
|
|
72
|
-
For more info on dateformating see '
|
44
|
+
For more info on dateformating with JalaliDate see it's docs
|
73
45
|
|
74
46
|
Copyright (c) 2012 Hassan Zamani, released under the MIT license.
|
data/lib/version.rb
CHANGED
data/parsi-localize.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
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 = '
|
13
|
+
s.summary = 'Help localization in farsi locale'
|
14
14
|
s.description = 'Change I18n localize to use parsi digits and jalaly dates in farsi locale'
|
15
15
|
|
16
16
|
|
@@ -26,4 +26,5 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_development_dependency("rake")
|
27
27
|
s.add_dependency("i18n")
|
28
28
|
s.add_dependency("jalalidate")
|
29
|
+
s.add_dependency("parsi-digits")
|
29
30
|
end
|
data/test/parsi_localize_test.rb
CHANGED
@@ -13,7 +13,7 @@ class ParsiLocalizeTest < Test::Unit::TestCase
|
|
13
13
|
date = Date.new(2012, 2, 5)
|
14
14
|
assert_equal "۹۰/۱۱/۱۶", I18n.l(date)
|
15
15
|
assert_equal "۹۰/۱۱/۱۶", I18n.l(date, format: :default)
|
16
|
-
assert_equal "۱۶ بهمن",
|
16
|
+
assert_equal "۱۶ بهمن", I18n.l(date, format: :short)
|
17
17
|
assert_equal "یکشنبه، ۱۶ بهمن ۱۳۹۰", I18n.l(date, format: :long)
|
18
18
|
end
|
19
19
|
|
@@ -21,7 +21,7 @@ class ParsiLocalizeTest < Test::Unit::TestCase
|
|
21
21
|
time = Time.new(2012, 2, 5, 15, 43, 30)
|
22
22
|
assert_equal "۹۰/۱۱/۱۶ ۱۵:۴۳:۳۰", I18n.l(time)
|
23
23
|
assert_equal "۹۰/۱۱/۱۶ ۱۵:۴۳:۳۰", I18n.l(time, format: :default)
|
24
|
-
assert_equal "۱۶ بهمن، ۱۵:۴۳",
|
24
|
+
assert_equal "۱۶ بهمن، ۱۵:۴۳", I18n.l(time, format: :short)
|
25
25
|
assert_equal "یکشنبه، ۱۶ بهمن ۱۳۹۰، ساعت ۱۵:۴۳:۳۰ (IRST)", I18n.l(time, format: :long)
|
26
26
|
end
|
27
27
|
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.
|
4
|
+
version: '0.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-
|
12
|
+
date: 2012-01-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &8926860 !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: *
|
24
|
+
version_requirements: *8926860
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &8926440 !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: *
|
35
|
+
version_requirements: *8926440
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: i18n
|
38
|
-
requirement: &
|
38
|
+
requirement: &8926020 !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: *
|
46
|
+
version_requirements: *8926020
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jalalidate
|
49
|
-
requirement: &
|
49
|
+
requirement: &8925600 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,18 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *8925600
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: parsi-digits
|
60
|
+
requirement: &8925180 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *8925180
|
58
69
|
description: Change I18n localize to use parsi digits and jalaly dates in farsi locale
|
59
70
|
email: hsn.zamani@gmail.com
|
60
71
|
executables: []
|
@@ -63,16 +74,13 @@ extra_rdoc_files: []
|
|
63
74
|
files:
|
64
75
|
- .gitignore
|
65
76
|
- Gemfile
|
77
|
+
- LICENSE
|
66
78
|
- README.markdown
|
67
79
|
- Rakefile
|
68
|
-
- init.rb
|
69
|
-
- lib/parsi_digits.rb
|
70
80
|
- lib/parsi_localize.rb
|
71
81
|
- lib/version.rb
|
72
|
-
- locale/en.yml
|
73
82
|
- locale/fa.yml
|
74
83
|
- parsi-localize.gemspec
|
75
|
-
- test/parsi_digits_test.rb
|
76
84
|
- test/parsi_localize_test.rb
|
77
85
|
- test/test_helper.rb
|
78
86
|
homepage: http://github.com/hzamani/parsi_localize
|
@@ -98,8 +106,7 @@ rubyforge_project:
|
|
98
106
|
rubygems_version: 1.8.10
|
99
107
|
signing_key:
|
100
108
|
specification_version: 3
|
101
|
-
summary:
|
109
|
+
summary: Help localization in farsi locale
|
102
110
|
test_files:
|
103
|
-
- test/parsi_digits_test.rb
|
104
111
|
- test/parsi_localize_test.rb
|
105
112
|
- test/test_helper.rb
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'parsi_localize'
|
data/lib/parsi_digits.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Parsi
|
4
|
-
module Digits
|
5
|
-
PARSI_DIGITS = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']
|
6
|
-
|
7
|
-
class << self
|
8
|
-
def to_parsi digit
|
9
|
-
PARSI_DIGITS[digit.to_i] if digit =~ /[0-9]/
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_western digit
|
13
|
-
PARSI_DIGITS.index digit if digit =~ /[۰-۹]/
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class String
|
20
|
-
def with_parsi_digits
|
21
|
-
gsub(/\d/) { |d| Parsi::Digits.to_parsi d }
|
22
|
-
end
|
23
|
-
|
24
|
-
def with_parsi_digits!
|
25
|
-
gsub!(/\d/) { |d| Parsi::Digits.to_parsi d }
|
26
|
-
end
|
27
|
-
|
28
|
-
def with_western_digits
|
29
|
-
gsub(/[۰-۹]/) { |d| Parsi::Digits.to_western d }
|
30
|
-
end
|
31
|
-
|
32
|
-
def with_western_digits!
|
33
|
-
gsub!(/[۰-۹]/) { |d| Parsi::Digits.to_western d }
|
34
|
-
end
|
35
|
-
|
36
|
-
def has_parsi_digits?
|
37
|
-
self =~ /[۰-۹]/
|
38
|
-
end
|
39
|
-
|
40
|
-
alias_method :western_to_i, :to_i
|
41
|
-
def to_i base=10
|
42
|
-
if has_parsi_digits?
|
43
|
-
with_western_digits.western_to_i base
|
44
|
-
else
|
45
|
-
western_to_i base
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
alias_method :western_to_f, :to_f
|
50
|
-
def to_f
|
51
|
-
if has_parsi_digits?
|
52
|
-
with_western_digits.sub("/",".").western_to_f
|
53
|
-
else
|
54
|
-
western_to_f
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
class Integer
|
60
|
-
def with_parsi_digits
|
61
|
-
to_s.with_parsi_digits
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
class Float
|
66
|
-
def with_parsi_digits
|
67
|
-
to_s.with_parsi_digits.sub '.', '/'
|
68
|
-
end
|
69
|
-
end
|
data/locale/en.yml
DELETED
File without changes
|
data/test/parsi_digits_test.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class ParsiDigitsTest < Test::Unit::TestCase
|
6
|
-
def test_string_with_parsi_digits
|
7
|
-
assert_equal "۹۸۷۶۵۴۳۲۱۰", "9876543210".with_parsi_digits
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_string_with_western_digits
|
11
|
-
assert_equal "9876543210", "۹۸۷۶۵۴۳۲۱۰".with_western_digits
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_parsi_string_to_i
|
15
|
-
assert_equal 9876543210, "۹۸۷۶۵۴۳۲۱۰".to_i
|
16
|
-
assert_equal 9876543210, "9876543210".to_i
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_parsi_string_to_f
|
20
|
-
assert_equal 0.987654321, "۰/۹۸۷۶۵۴۳۲۱".to_f
|
21
|
-
assert_equal 0.987654321, "0.987654321".to_f
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_integer_with_parsi_digits
|
25
|
-
assert_equal "۹۸۷۶۵۴۳۲۱۰", 9876543210.with_parsi_digits
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_float_with_parsi_digits
|
29
|
-
assert_equal "۹/۰۸۷۶۵۴۳۲۱", 9.087654321.with_parsi_digits
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_has_parsi_digits
|
33
|
-
assert "۱۹۴".has_parsi_digits?
|
34
|
-
assert "test۹۸".has_parsi_digits?
|
35
|
-
assert !"123".has_parsi_digits?
|
36
|
-
assert !"test".has_parsi_digits?
|
37
|
-
end
|
38
|
-
end
|