Localization of numeric number in Rails

蹲街弑〆低调 提交于 2019-12-05 16:11:22

Ok, I've come up with that:

  def number to_convert, locale, text = nil,
    to_convert = to_convert.to_i.to_s
    case locale
    when 'ar'
      to_convert = to_convert.unpack('U*').map{ |e| e + 1584 }.pack('U*')
      text ? to_convert + ' ' + text : to_convert
    when 'fa'
      to_convert = to_convert.unpack('U*').map{ |e| e + 1728 }.pack('U*')
      text ? to_convert + ' ' + text : to_convert
    when 'hi'
      to_convert = to_convert.unpack('U*').map{ |e| e + 2358 }.pack('U*')
      text ? to_convert + ' ' + text : to_convert
    else
      text ? to_convert + ' ' + text : to_convert
    end
  end

Other language don't need custom localization. Ie. Chineese/Japanese people understand our number and it will be weird to support their local number as local people are using our number on the web.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!