config\locales\translation_ja.ymlファイルを下記のように編集して、
ja:
activerecord:
models:
demandapp: "要望" #g
attributes:
demandapp:
acquisition: "補足" #g
class1: "大分類" #g
class2: "分類" #g
content: "内容" #g
derivery: "納期" #g
report_count: "件数 #g"
source: "提起" #g
state: "状態" #g
これをviewのindexから下記のように、I18n.tメソッドを使って日本語訳を呼び出そうとすると、
<% Demandapp.column_names.each do |col| %>
<th>
<%= t("activerecord.attributes.demandapp.#{col}") %> # <ーここ
</th>
<% end %>
I18n::InvalidLocaleData in Demandapps#index
can not load translations from c:/user/Ruby193/rails/demand/config/locales/translation_ja.yml, expected it to return a hash, but does not
#の所でエラーが出て理由が分かりかねています。
ご経験のある方、御教示願えればと思います。
No.1ベストアンサー
- 回答日時:
translation_ja.ymlの記述に問題があります。
ymlはインデントが命です。インデントは半角の空白のみ使用可能です。
タブ、全角空白を、使用すると正しく動作しません。以下のように記述してください。
---------------------------------------
ja:
activerecord:
models:
demandapp: "要望" #g
attributes:
demandapp:
acquisition: "補足" #g
class1: "大分類" #g
class2: "分類" #g
content: "内容" #g
derivery: "納期" #g
report_count: "件数" #g
source: "提起" #g
state: "状態" #g
----------------------------------------
尚、このgooのサイトは半角のインデントは使えないので、全角で投稿しています。
あなたが、この記述をするときは、必ず半角の空白で記述してください。
又、
report_count: "件数 #g" ですが
これは
report_count: "件数" #g
の誤りと理解しました。
参考までに
index.html.erbの内容と実行結果です。
------------------------
<h1>Listing demandapps</h1>
<table>
<tr>
<th>Acquisition</th>
<th>Class1</th>
<th>Class2</th>
<th>Content</th>
<th>Derivery</th>
<th>Derivery</th>
<th>Report count</th>
<th>Source</th>
<th>State</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @demandapps.each do |demandapp| %>
<tr>
<td><%= demandapp.acquisition %></td>
<td><%= demandapp.class1 %></td>
<td><%= demandapp.class2 %></td>
<td><%= demandapp.content %></td>
<td><%= demandapp.derivery %></td>
<td><%= demandapp.derivery %></td>
<td><%= demandapp.report_count %></td>
<td><%= demandapp.source %></td>
<td><%= demandapp.state %></td>
<td><%= link_to 'Show', demandapp %></td>
<td><%= link_to 'Edit', edit_demandapp_path(demandapp) %></td>
<td><%= link_to 'Destroy', demandapp, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
<br />
<% Demandapp.column_names.each do |col| %>
<th>
<%= t("activerecord.attributes.demandapp.#{col}") %>
<%#= Demandapp.human_attribute_name("#{col}") %>
</th>
<% end %>
<br />
<%= link_to 'New Demandapp', new_demandapp_path %>
------------------------
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
似たような質問が見つかりました
- Excel(エクセル) Excelにて、フォルダ内のTextファイルをマクロで統合すると文字化けしてしまう時の解消コード 4 2023/01/01 07:32
- Excel(エクセル) エクセルのマクロについて教えてください。 2 2023/01/11 08:33
- Visual Basic(VBA) エクセルVBAで教えて頂きたいのですが? 2 2022/12/31 20:28
- Visual Basic(VBA) ExcelVBAに関する質問 3 2023/02/17 10:47
- Visual Basic(VBA) ファイル全てを .xlsm に変更したところ、プログラムが途中で落ちてしまっています 17 2022/12/07 12:03
- Visual Basic(VBA) 【Excel VBA】自動メール送信の機能追加 5 2022/09/29 12:53
- C言語・C++・C# C++のcase文の書き方 4 2023/02/24 20:50
- Excel(エクセル) 【マクロ】フォルダAからダBへファイルを、ファイルの更新日時の条件で、1つづつ移動するには? 3 2022/08/25 09:56
- Excel(エクセル) エクセル VBA For Next 繰り返しの書き方を教えてください 6 2022/09/01 14:11
- Access(アクセス) アクセス where句を使用して複数条件抽出をするには 2 2022/08/29 13:24
関連するカテゴリからQ&Aを探す
おすすめ情報
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
rails3初心者 金額から絞り込み...
-
get() と find() の違いについて
-
エクセルVBA オートフィルタで...
-
「arg」は何の略?
-
パイソンのクラス
-
Rubyについて質問です
-
No route matches [GET] "/post...
-
pythonのerrorコード
-
メソッド定義の構文のdefって
-
教えてください。vb5.0
-
classのdelete
-
クエリーストリングとは?
-
RubyでバイナリデータをIOスト...
-
Rubyの超初心者です。「戻り値r...
-
cos波表示について マクローリ...
-
実行時エラー450:引数の数が一...
-
エラー「メソッドまたはデータ...
-
Csvファイルの最終行を取得する...
-
ぱいソン
-
What class are you in? には何...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
10円未満を切り捨てる方法は?
-
Rails3でのYAMLファイルのtメソ...
-
windows embdded standard7
-
Rails コンボボックスの値の保...
-
pythonのerrorコード
-
get() と find() の違いについて
-
「arg」は何の略?
-
エラー「メソッドまたはデータ...
-
What class are you in? には何...
-
パイソンのクラス
-
教えてください。vb5.0
-
No route matches [GET] "/post...
-
クラス名やモジュール名の競合...
-
VBAで型が一致しないエラー(バ...
-
Rubyについて質問です
-
実行時エラー450:引数の数が一...
-
ぱいソン
-
エクセルVBA オートフィルタで...
-
メソッド定義の構文のdefって
-
Csvファイルの最終行を取得する...
おすすめ情報