簡単なCRUD処理を実装させた、アプリケーションを作成して練習しています。
DRUDの実装が完了し、bootstrapを適用させてみよう、という流れで進めてみて、細かい部分を日本語に直していくというところで、f.submitの文字が日本語に変更されず、解決できないので、一緒に見てもらえませんか。
このようにsubmitのupdateがおおきく表示されています。これを日本語適用させたいです。
以下、自分でやってみたことです
application.rbを編集
require_relative 'boot' require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module TaskApp class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 5.2 config.i18n.load_path += Dir[Rails.root.join('config','locales','*.{rb,yml}').to_s] config.i18n.default_locale = :ja # 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 end
en.ymlを複製し、ja.ymlを作成、編集
# Files in the config/locales directory are used for internationalization ja: time: formats: default: "%Y/%m/%d %H:%M:%S" am: 午前 pm: 午後 activerecord: models: task: タスク attributes: task: title: タイトル content: コンテンツ helpers: select: prompt: 選択してください submit: create: 登録する submit: 保存する update: 更新
edit.html.erb
<h1>タスク編集画面</h1> 注:登録ボタンを押すとupdateアクションに処理が飛ぶ <%= form_for @task do |f| %> <div> <%= f.text_field :title %> <%= f.label :title %> </div> <div> <%= f.text_field :content %> <%= f.label :content %> </div> <div> <%= f.submit class: 'btn btn-primary btn-sm' %> </div> <%= link_to '戻る',tasks_path, class: "btn-sm btn-light" %> <% end %>
回答1件
あなたの回答
tips
プレビュー