[Ruby on Rails] Japanische Fehlernotation

Ziel

日本語.gif

Entwicklungsumgebung

ruby 2.5.7 Rails 5.2.4.3 OS: macOS Catalina

Annahme

[Ruby on Rails] Individuelle Anzeige von Fehlermeldungen Es ist leicht zu verstehen, wenn Sie es beim Vergleich mit diesem Artikel betrachten.

fließen

Einführung von 1 Edelstein 2 Bearbeiten Sie config / application.rb 3 Erstellen und bearbeiten Sie config / locales / ja.yml

Einführung von Edelstein

Gemfile


gem 'rails-i18n'

Terminal


$ bundle install

Bearbeiten Sie config / application.rb

Die folgenden zwei Zeilen wurden hinzugefügt.

config/application.rb


  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.2
    config.i18n.default_locale = :ja #← Hinzufügen
    config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] #← Hinzufügen
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration can go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded after loading
    # the framework and any gems in your application.
  end

config/locales/ja.yml

config/locales/ja.yml


ja:
  activerecord:
    attributes:
      user:
        email: 'Mail Adresse'
        password: 'Passwort'
        password_confirmation: 'Passwort(Zur Bestätigung)'
        name: 'Name'
Ergänzung [user:] Es wird der Modellname sein. Wenn Sie mit demselben Einzug schreiben Eine japanische Notation für andere Modelle ist ebenfalls möglich.

Recommended Posts