Reputation: 4930
I want to change the default numbers from english to arabic when the user switches to the arabic interface.
13 => ١٣
89 => ٨٩
What is the best way to tackle this problem?
Upvotes: 1
Views: 1359
Reputation: 11858
I add in helper module
ARABIC_NUMBERS = %w(٠ ١ ٢ ٣ ٤ ٥ ٦ ٧ ٨ ٩)
def ta numbers
numbers = numbers.to_s if numbers.is_a? Integer
results = numbers.chars.map { |char| ARABIC_NUMBERS[char.to_i] }.join
end
Upvotes: 1
Reputation: 4930
I came up with this quick solution. I added the following function in the ApplicationHelper
def tn(num)
num.to_s.split(//).map{|r|t("n"+r)}.join
end
Then added translations for each number from 0 to 9 in the config/locals/ar.yml
with the format below:
n1: "١"
n2: "٢"
n3: "٣"
.
.
.
Now we can call the new numeric translation function by tn(13)
which will output ١٣
in arabic localization
Upvotes: 0
Reputation: 7230
Check this code : https://github.com/gdotdesign/rails-arabic-convert/blob/master/app/helpers/convert_helper.rb.
It's a helper to convert a english number to an arabic number.
Upvotes: 0