I
I
Infinite2013-10-18 10:02:30
Ruby on Rails
Infinite, 2013-10-18 10:02:30

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 %>


How to make a label in Russian?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
DeFANCE, 2013-10-18
@Infinite

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

A
Artur Bordenyuk, 2013-10-18
@HighQuality

Change locale?
en.yml

activerecord:
  attributes:
    post:
      email: 'Электропочта'

N
Nikolai Turnaviotov, 2013-10-18
@foxmuldercp

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 question

Ask a Question

731 491 924 answers to any question