localize_multi_digit 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/localize_multi_digit.rb +34 -0
- metadata +45 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#
|
4
|
+
# Fixnum, Float, String, Date, Time and DateTime class will be extended by this module
|
5
|
+
#
|
6
|
+
module LocalizeMultiDigit
|
7
|
+
|
8
|
+
# Returns String
|
9
|
+
# Converts to Bangla digits only when applied to Fixnum, Float, String, Date, Time and DateTime object
|
10
|
+
|
11
|
+
def self.to_ld(text)
|
12
|
+
item = text || ""
|
13
|
+
digit_map = {
|
14
|
+
:bn => {'0' => '০', '1' => '১', '2' => "২", '3' => '৩', '4' => '৪', '5' => '৫', '6' => '৬', '7' => '৭', '8' => '৮', '9' => '৯'},
|
15
|
+
:en => {'0' => '0', '1' => '1', '2' => "2", '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9'},
|
16
|
+
:ar => {'0' => '٠', '1' => '١', '2' => "٢", '3' => '٣', '4' => '٤', '5' => '٥', '6' => '٦', '7' => '٧', '8' => '٨', '9' => '٩'},
|
17
|
+
:hn => {'0' => '०', '1' => '१', '2' => "२", '3' => '३', '4' => '४', '5' => '५', '6' => '६', '7' => '७', '8' => '८', '9' => '९'}
|
18
|
+
}
|
19
|
+
translated_item = ""
|
20
|
+
begin
|
21
|
+
locale = I18n.locale
|
22
|
+
rescue Exception => error
|
23
|
+
locale = :en
|
24
|
+
end
|
25
|
+
item.to_s.split("").each do |c|
|
26
|
+
if c.to_i > 0 || c == '0'
|
27
|
+
translated_item += digit_map[locale][c]
|
28
|
+
else
|
29
|
+
translated_item += c
|
30
|
+
end
|
31
|
+
end
|
32
|
+
return translated_item
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: localize_multi_digit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Abdul Barek
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-21 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email:
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/localize_multi_digit.rb
|
21
|
+
homepage:
|
22
|
+
licenses: []
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 1.8.17
|
42
|
+
signing_key:
|
43
|
+
specification_version: 3
|
44
|
+
summary: localize_multi_digit localizes digits
|
45
|
+
test_files: []
|