0

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

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

虽然翻译正常,但消息显示为标题,例如:

* 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 名称。

再次提前感谢您!

4

1 回答 1

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
于 2013-12-22T08:52:12.547 回答