2008年12月4日木曜日

restful_authenticationの日本語化。の続き。

で、config/locales/model_ja.ymlを見ていて、ふっ、と気が付いた。
loginとかemailとかnameとかなんて、モデルに限定されずに、使い回す訳じゃない?

ほら、DRYじゃない?
オイラって、DRYな訳じゃない?
むしろ、女の娘にDRYにあしらわれ続けてきた訳じゃない?www

じゃあ、DRYにしようよ、ってことを考えた。
でも、なんか、model_ja.ymlの中の、activerecord:attribute:hogehogeって、DBスキーマと結びついている筈だから、なあ...

でも、逆に考えれば、DBスキーマに結びついていないものは、共有できるよね。
で、こんな風に書き換えた。
ja:
  activerecord:
    models:
      user: ユーザ
      session: セッション
    attributes:
      user:
        login: ログイン
        name: 名前
        email: メールアドレス
        deleted_at: で削除された
        password: パスワード
        password_confirmation: 確認用パスワード
        crypted_password: 暗号化パスワード
        salt: 塩
        remember_token: 覚えているトークン
        remember_token_expires_at: トークンを忘れないで期限が切れる
        activation_code: 認証コード
        activated_at: でアクティブ
        state: 状態
      session:
        
  actionview:
    header:
      user:
        new: 新規ユーザー登録
      session:
        new: ログイン
    label:
      common:
        login: ログイン
        name: 名前
        email: メールアドレス
        password: パスワード
        password_confirmation: 確認用パスワード
      session:
        remember_me: ログイン状態を記憶する
    submit:
      common:
        submit: 送信
      user:
        signup: 登録
      session:
        log_in: ログイン

あんまりDRYな気がしないよね...www
まあ、でも、viewの中で使っているもの=hogehoge_tagメソッドとかに使いそうなものは、ja:action_view:サブクラスを作って、その中に突っ込んだよ。
viewで使うものは、activerecordとは絡めない方が、規約っぽいでしょ?

設定より規約っ!www

んで、viewも書き換えたよ。
<h1><%= t('actionview.header.user.new') %></h1>
<% @user.password = @user.password_confirmation = nil %>

<%= error_messages_for :user %>
<% form_for :user, :url => users_path do |f| -%>
<p><%= label_tag 'login', t('actionview.label.common.login') %><br/>
<%= f.text_field :login %></p>

<p><%= label_tag 'email', t('actionview.label.common.email') %><br/>
<%= f.text_field :email %></p>

<p><%= label_tag 'passoword', t('actionview.label.common.password') %><br/>
<%= f.password_field :password %></p>

<p><%= label_tag 'password_confirmation', t('actionview.label.common.password_confirmation') %><br/>
<%= f.password_field :password_confirmation %></p>

<p><%= submit_tag t('actionview.submit.user.signup') %></p>
<% end -%>

んで、app/views/sessions/new.html.erbも、書き換えた。
<h1><%= t('actionview.header.user.new') %></h1>
<% @user.password = @user.password_confirmation = nil %>

<%= error_messages_for :user %>
<% form_for :user, :url => users_path do |f| -%>
<p><%= label_tag 'login', t('actionview.label.common.login') %><br/>
<%= f.text_field :login %></p>

<p><%= label_tag 'email', t('actionview.label.common.email') %><br/>
<%= f.text_field :email %></p>

<p><%= label_tag 'passoword', t('actionview.label.common.password') %><br/>
<%= f.password_field :password %></p>

<p><%= label_tag 'password_confirmation', t('actionview.label.common.password_confirmation') %><br/>
<%= f.password_field :password_confirmation %></p>

<p><%= submit_tag t('actionview.submit.user.signup') %></p>
<% end -%>
んじゃあ、ちょっとこの辺でペンディング。
別の事を始める事にしよう。

0 件のコメント: