Answer the question
In order to leave comments, you need to log in
Using Russian label when generating a form
I'm learning ROR and the following question came up, the following code is used to generate the form in the tutorial
<%= form_for(:session, url: sessions_path) do |f| %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.submit "Sign in", class: "btn btn-large btn-primary" %>
<% end %>
Answer the question
In order to leave comments, you need to log in
As noted, locales should be used. And it is highly recommended to take out all lines of text from templates. The most painless option is to use i18n (everything has been messed up for a long time).
en: guides.rubyonrails.org/i18n.html
en: rusrails.ru/rails-internationalization-i18n-api
Change locale?
en.yml
activerecord:
attributes:
post:
email: 'Электропочта'
Hm. Is there a code "above" this "generated" one?
And C# has such a wonderful thing as Data Annotations.
…
[Required]
[Display(Name = "Username")]
public string UserName { get; set; }
…
That is, in form submission, the code would look like this:
…
@ Html.LabelFor(m => m.UserName, new { @ class = "control-label" })
@ Html.TextBoxFor(m => m.UserName )
@ Html.ValidationMessageFor(m => m.UserName, null, new { @ class = "help-inline" })
...
And the LabelFor m.UserName text will be replaced with the one written in the Display Name, instead of the default English.
At the same time, repeating your situation, the label on the “sign in” button in the original was also English, I translated it with my hands
/>
Try to dig in this direction too.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question