Rails 3将默认的英语数字更改为阿拉伯数字 [英] Rails 3 change default english numbers to arabic numbers

查看:89
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆