gpt4 book ai didi

html - 如何更改所需错误消息的语言?

转载 作者:行者123 更新时间:2023-11-28 05:30:36 25 4
gpt4 key购买 nike

我使用 Ruby on Rails 创建了应用程序。一切都是英文的,但是当我在字段中输入内容时,错误消息是德语的。如何更改此消息的语言(英语)?这是我的 View 代码:

<%=form_for(@electricity_generation) do |f| %>
<% if @electricity_generation.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@electricity_generation.errors.count, "error") %>
prohibited this electricity_generation from being saved:</h2>

<ul>
<% @electricity_generation.errors.full_messages.each do |message| %>
<li>
<%=m essage %>
</li>
<% end %>
</ul>
</div>
<% end %>
<section>
<h2 align="center">
Chosen Scenario:
<%=link_to @scenario_selections, scenarios_path %>
</h2>
<br>
<div class="table-row-2">
<div align="center">
<div class="field">
<div class="table">
<strong>Information</strong>
</div>
<div class="table">
<strong>Value</strong>
</div>
<div class="table">
<strong>Positive Deviation (1=100%)</strong>
</div>
<div class="table">
<strong>Negative Deviation (1=100%)</strong>
</div>
<div class="table">
<%=label_tag(:annual_solar_irradiation, 'Annual Solar Irradiation (kwh/m^2):') %>
</div>
<div class="table">
<%=f.text_field :annual_solar_irradiation, type: "number", required: "required", placeholder: "kWh/m^2" %>
</div>
<div class="table">
<%=f.text_field :asi_max, type: "number", min: "0", max: "1", step: "0.01", required: "required"%>
</div>
<div class="table">
<%=f.text_field :asi_min, type: "number", min: "0", max: "1", step: "0.01", required: "required" %>
</div>
</div>
</div>
</div>
<div align="center">
<div class="actions">
<%=f .submit %>
</div>
</div>
</section>
<% end %>

这是它的显示方式:

enter image description here

这是 application.rb:

enter image description here

最佳答案

您使用 HTML constraint validation在你的表格中。您看到的错误消息是由浏览器创建的。浏览器以其安装的语言提供此错误消息。

如果需要,您可以使用 input 标记的 title 属性覆盖(或添加信息;取决于浏览器)此消息。

<%=f.text_field :asi_max, type: "number", min: "0", max: "1", step: "0.01", title: "Please enter a number between 0 and 1.", required: "required" %>

如果您想完全控制此消息,您需要使用 Javascript(另见 this 问题)。有图书馆(如 parsleyjs )可以帮助您做到这一点。

关于html - 如何更改所需错误消息的语言?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38527625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com