3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FuelPHPのORMを日本語化する

Last updated at Posted at 2014-12-25

というよりは、日本語化しやすくする工夫

日本語を定義

  • フィールド名に日本語を定義
  • 関連して使用する項目があれば自由に追加定義(password2など)
  • _nameにテーブル名を定義
  • 以上をテーブルの分だけ記述
fuel/app/lang/ja/model.php
<?php
return array(
	'user' => array(
		'_name'                => 'ユーザー',
		'username'             => 'ユーザー名',
		'nickname'             => 'ニックネーム',
		'email'                => 'メールアドレス',
		'group'                => '権限グループ',
		'password'             => 'パスワード',
		'password2'            => 'パスワード確認',
		'last_login'           => '最終ログイン日',
		'login_hash'           => 'ログインハッシュ',
		'profile_fields'       => 'プロフィール',
		
		'_anonymouse'          => '匿名',
	),
	
	'topic' => array(
		'_name'                => 'スレッド',
		'title'                => 'タイトル',
		'body'                 => '本文',

バリデーションで使用

fuel/app/classes/model/topic.php
	public static function validate($factory)
	{
		$val = Validation::forge($factory);
		$val->add_field('title'            , __('model.topic.title'            ), 'required|max_length[255]');
		$val->add_field('body'             , __('model.topic.body'             ), 'required|max_length[1000]');

		return $val;
	}

ビューで使用

<?php echo __('model.topic.body'); ?>
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?