RoR验证错误翻译得到了标题化

时间:2013-07-03 10:10:58

标签: ruby-on-rails-3.2 translation rails-activerecord

最后,我开始使用RoR I18n翻译。

我很难翻译在表单填写过程中出现错误时出现的Activerecord验证错误。

虽然翻译没问题,但消息显示为titelized,例如:

* Parol Va Tasdig'i Bo'sh Bo'lishi Mumkin Emas
* Ism Uzun (Ko'pi Bilan 50 Belgi)
* Email Manzil Xato Kiritilgan

有没有办法'大写'这些消息?所以看起来应该是这样的:

* Parol tasdig'i bo'sh bo'lishi mumkin emas

作为一个注释,我怀疑我正在做的方式有一些缺陷,例如,这是上述消息的html输出:

<li>* <span class="translation_missing" title="translation missing: uzlt.Parol va tasdig'i bo'sh bo'lishi mumkin emas">Parol Va Tasdig'i Bo'sh Bo'lishi Mumkin Emas</span></li><li>* <span class="translation_missing" title="translation missing: uzlt.Ism uzun (ko'pi bilan 50 belgi)">Ism Uzun (Ko'pi Bilan 50 Belgi)</span></li><li>* <span class="translation_missing" title="translation missing: uzlt.Email manzil xato kiritilgan">Email Manzil Xato Kiritilgan</span></li>
<li>* <span class="translation_missing" title="translation missing: uzlt.Parol bo'sh bo'lishi mumkin emas">Parol Bo'sh Bo'lishi Mumkin Emas</span></li><li>* <span class="translation_missing" title="translation missing: uzlt.Parol qisqa (minimum 6 belgi)">Parol Qisqa (Minimum 6 Belgi)</span></li><li>* <span class="translation_missing" title="translation missing: uzlt.Parol tasdig'i bo'sh bo'lishi mumkin emas">Parol Tasdig'i Bo'sh Bo'lishi Mumkin Emas</span></li>

如您所见,那里有一些 translation_missing 字符串。

以下是输出消息的Slim片段:

  1 - if object.errors.any?
  2   #error_explanation
  3     .alert.alert-error
  4       #{object.errors.count} dona xato mavjud
  5     ul
  6       - object.errors.full_messages.each do |msg|
  7         li * #{t(msg)}
  8       end                                                                                                    
  9 end

当我查询msg对象类型时,它给了我ActiveSupport :: SafeBuffer名称。

提前再次感谢您!

1 个答案:

答案 0 :(得分:0)

我更改了li元素输出以解决问题:

- if object.errors.any?
  #error_explanation
    .alert.alert-error
      #{t('messages.error_on_form', count: object.errors.count)}
    ul
      - object.errors.full_messages.each do |msg|
        li == "* #{t(msg).capitalize}"
      end
end