fc2ブログ

2023.08 «  - - - - - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 » 2023.10
TOP > Ruby-GetText初体験その5【ファイルをUTF-8で日本語書き換え】

 ← Ruby-GetText初体験その6【po ファイルと mo ファイル】 | TOP | Ruby-GetText初体験その4【require 'gettext/rails' と init_gettext】

Ruby-GetText初体験その5【ファイルをUTF-8で日本語書き換え】 

2007年09月24日 ()

その1【インストールしてみる】
その2【英語のアプリをまず作成】
その3【日本語を使うぞ宣言】
その4【require 'gettext/rails' と init_gettext】
その5【ファイルをUTF-8で日本語書き換え】
その6【po ファイルと mo ファイル】



前回 Ruby-GetText ライブラリを使いました。

今回は、Ruby-GetText からいきなり一旦離れて、単純に rhtml ファイルを日本語で書き換える地味な作業を行います。

書き換える時は、ファイルの文字コードを UTF-8 に設定することをお忘れなく!

では、早速書き換えます。

app/views/layouts/book_mng.rhtml
BEFORE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  <title>BookMng: <%= controller.action_name %></title>
  <%= stylesheet_link_tag 'scaffold' %>
</head>
<body>

<p style="color: green"><%= flash[:notice] %></p>

<%= yield %>

</body>
</html>


↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

app/views/layouts/book_mng.rhtml
AFTER

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  <title>本の管理: <%= controller.action_name %></title>
  <%= stylesheet_link_tag 'scaffold' %>
</head>
<body>

<p style="color: green"><%= flash[:notice] %></p>

<%= yield %>

</body>
</html>







app/views/book_mng/list.rhtml
BEFORE

<h1>Listing books</h1>

<table>
  <tr>
  <% for column in Book.content_columns %>
    <th><%= column.human_name %></th>
  <% end %>
  </tr>

<% for book in @books %>
  <tr>
  <% for column in Book.content_columns %>
    <td><%=h book.send(column.name) %></td>
  <% end %>
    <td><%= link_to 'Show', :action => 'show', :id => book %></td>
    <td><%= link_to 'Edit', :action => 'edit', :id => book %></td>
    <td><%= link_to 'Destroy', { :action => 'destroy', :id => book }, :confirm => 'Are you sure?', :method => :post %></td>
  </tr>
<% end %>
</table>

<%= link_to 'Previous page', { :page => @book_pages.current.previous } if @book_pages.current.previous %>
<%= link_to 'Next page', { :page => @book_pages.current.next } if @book_pages.current.next %>

<br />

<%= link_to 'New book', :action => 'new' %>


↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

app/views/book_mng/list.rhtml
AFTER

<h1>本の一覧</h1>

<table>
  <tr>
  <% for column in Book.content_columns %>
    <th><%= column.human_name %></th>
  <% end %>
  </tr>

<% for book in @books %>
  <tr>
  <% for column in Book.content_columns %>
    <td><%=h book.send(column.name) %></td>
  <% end %>
    <td><%= link_to '詳細', :action => 'show', :id => book %></td>
    <td><%= link_to '編集', :action => 'edit', :id => book %></td>
    <td><%= link_to '削除', { :action => 'destroy', :id => book }, :confirm => '本当に削除しますか?', :method => :post %></td>
  </tr>
<% end %>
</table>

<%= link_to '前のページ', { :page => @book_pages.current.previous } if @book_pages.current.previous %>
<%= link_to '次のページ', { :page => @book_pages.current.next } if @book_pages.current.next %>

<br />

<%= link_to '本を追加', :action => 'new' %>







app/views/book_mng/show.rhtml
BEFORE

<% for column in Book.content_columns %>
<p>
  <b><%= column.human_name %>:</b> <%=h @book.send(column.name) %>
</p>
<% end %>

<%= link_to 'Edit', :action => 'edit', :id => @book %> |
<%= link_to 'Back', :action => 'list' %>


↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

app/views/book_mng/show.rhtml
AFTER

<% for column in Book.content_columns %>
<p>
  <b><%= column.human_name %>:</b> <%=h @book.send(column.name) %>
</p>
<% end %>

<%= link_to '編集', :action => 'edit', :id => @book %> |
<%= link_to '戻る', :action => 'list' %>







app/views/book_mng/new.rhtml
BEFORE

<h1>New book</h1>

<% form_tag :action => 'create' do %>
  <%= render :partial => 'form' %>
  <%= submit_tag "Create" %>
<% end %>

<%= link_to 'Back', :action => 'list' %>


↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

app/views/book_mng/new.rhtml
AFTER

<h1>本の追加</h1>

<% form_tag :action => 'create' do %>
  <%= render :partial => 'form' %>
  <%= submit_tag "追加する" %>
<% end %>

<%= link_to '戻る', :action => 'list' %>







app/views/book_mng/new.rhtml
BEFORE

<h1>Editing book</h1>

<% form_tag :action => 'update', :id => @book do %>
  <%= render :partial => 'form' %>
  <%= submit_tag 'Edit' %>
<% end %>

<%= link_to 'Show', :action => 'show', :id => @book %> |
<%= link_to 'Back', :action => 'list' %>


↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

app/views/book_mng/new.rhtml
AFTER

<h1>本の編集</h1>

<% form_tag :action => 'update', :id => @book do %>
  <%= render :partial => 'form' %>
  <%= submit_tag '更新する' %>
<% end %>

<%= link_to '詳細', :action => 'show', :id => @book %> |
<%= link_to '戻る', :action => 'list' %>






app/views/book_mng/_form.rhtml
BEFORE

<%= error_messages_for 'book' %>

<!--[form:book]-->
<p><label for="book_title">Title</label><br/>
<%= text_field 'book', 'title' %></p>

<p><label for="book_author_name">Author name</label><br/>
<%= text_field 'book', 'author_name' %></p>

<p><label for="book_author_gender">Author gender</label><br/>
<%= radio_button 'book', 'author_gender', 'm' %>male<br/>
<%= radio_button 'book', 'author_gender', 'f' %>female<br/></p>

<p><label for="book_isbn">Isbn</label><br/>
<%= text_field 'book', 'isbn' %></p>

<p><label for="book_price">Price</label><br/>
<%= text_field 'book', 'price' %></p>
<!--[eoform:book]-->


↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

app/views/book_mng/_form.rhtml
AFTER

<%= error_messages_for 'book' %>

<!--[form:book]-->
<p><label for="book_title">タイトル</label><br/>
<%= text_field 'book', 'title' %></p>

<p><label for="book_author_name">著者名</label><br/>
<%= text_field 'book', 'author_name' %></p>

<p><label for="book_author_gender">著者の性別</label><br/>
<%= radio_button 'book', 'author_gender', 'm' %><br/>
<%= radio_button 'book', 'author_gender', 'f' %><br/></p>

<p><label for="book_isbn">Isbn</label><br/>
<%= text_field 'book', 'isbn' %></p>

<p><label for="book_price">価格</label><br/>
<%= text_field 'book', 'price' %></p>
<!--[eoform:book]-->




うーん、地味だ・・・

これで、大体書き換わりましたね。次回は、Ruby-GetText に戻って、まだ日本語化しきれていない場所を日本語にしていきたいと思います。

【広告】

[2007.09.24(Mon) 13:32] 日本語化Trackback(0) | Comments(0)
↑TOPへ

 ← Ruby-GetText初体験その6【po ファイルと mo ファイル】 | TOP | Ruby-GetText初体験その4【require 'gettext/rails' と init_gettext】

COMMENT

COMMENT POST















管理者にだけ表示

 ← Ruby-GetText初体験その6【po ファイルと mo ファイル】 | TOP | Ruby-GetText初体験その4【require 'gettext/rails' と init_gettext】