Rails 3 将默认英文数字更改为阿拉伯数字 [英] Rails 3 change default english numbers to arabic numbers
本文介绍了Rails 3 将默认英文数字更改为阿拉伯数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户切换到阿拉伯语界面时,我想将默认数字从英语更改为阿拉伯语.
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?
推荐答案
我想出了这个快速的解决方案.我在 ApplicationHelper 中添加了以下功能
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
然后在 config/locals/ar.yml
中为每个数字从 0 到 9 添加翻译,格式如下:
Then added translations for each number from 0 to 9 in the config/locals/ar.yml
with the format below:
n1: "١"
n2: "٢"
n3: "٣"
.
.
.
现在我们可以通过tn(13)
调用新的数字翻译函数,它将以阿拉伯语本地化输出١٣
Now we can call the new numeric translation function by tn(13)
which will output ١٣
in arabic localization
这篇关于Rails 3 将默认英文数字更改为阿拉伯数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文