Ruby on Rails/第7回勉強会 - gettextを使ったvalidationエラーの日本語化 http://www.ark-web.jp/sandbox/wiki/185.html

Ruby on Rails/第7回勉強会 - gettextを使ったvalidationエラーの日本語化

[edit]

Ruby on Rails勉強会一覧

[edit]

第7回勉強会のネタ

ネタもとは下記です。

[edit]

日時

[edit]

参加者

久末さん、どうもありがとうございます!また参加してねーー。 [bigsmile]

[edit]

動画

[edit]

gettextとは

[edit]

Ruby-GetTextとは?

[edit]

作業のながれ

[edit]

Ruby-GetTextのrailsへの組み込み

  1. config/environment.rbの先頭に
    $KCODE = 'u'            # UTF-8の場合。's' = SJIS, 'e' = EUC-JPなど
    require 'jcode'         # Stringクラスのメソッドなどを$KCODEに指定した
                            # 文字コードで適切に動作するように置き換えます
  2. config/environment.rbの末尾に
    require 'gettext/rails' # Ruby-GetText-Packageを使う宣言です。
  3. app/controllers/application.rbに
    class ApplicationController < ActionController::Base
     init_gettext "sample"
    end
    http://www.yotabanana.com/gettextapi/classes/ActionController/Base.html#M000016
[edit]

msgidを指定しながらコーディング

[edit]

コントローラ

http://www.yotabanana.com/hiki/ja/ruby-gettext-howto-ror.html#Controller

[edit]

ビュー

http://www.yotabanana.com/hiki/ja/ruby-gettext-howto-ror.html#Views/ActionMailer

[edit]

モデル

http://www.yotabanana.com/hiki/ja/ruby-gettext-howto-ror.html#Models

%{fn}
フィールド名
%{d}
長さチェックなどの境界値
%{title}
タイトル名
[edit]

error_messages_forのタイトルの日本語化

http://www.yotabanana.com/hiki/ja/ruby-gettext-howto-ror.html#%A5%A8%A5%E9...

 ActionView::Helpers::ActiveRecordHelper::L10n.set_error_message_title(
   N_("An error was found in %{record}"),
   N_("%{num} errors were found in %{record}"))
 ActionView::Helpers::ActiveRecordHelper::L10n.set_error_message_explanation(
   N_("The error is:"), 
   N_("The errors are:"))
[edit]

potファイルの生成

[edit]

moファイルの生成

$ rake makemo
$ ls locale/ja/LC_MESSAGES/sample.mo

投稿者志田 | パーマリンク

| append.gif

tag: Ruby on Rails, gettext, 勉強会


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2007-01-05 (金) 08:10:45 (6314d)

アークウェブのサービスやソリューションはこちら