8
7

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 valid_stringのエラー時に、使用可能文字を日本語化したい

Last updated at Posted at 2014-12-25
fuel/app/classes/validation/error.php
<?php

class Validation_Error extends Fuel\Core\Validation_Error
{
	/**
	 * Override
	 *
	 * @param   error message to parse
	 * @return  string
	 */
	protected function _replace_tags($msg)
	{
		$msg = parent::_replace_tags($msg);
		
		$find = __('validation.valid_string_params');
		if( $find ){
			foreach( $find as $param => $str ){
				$msg  = str_replace($param,$str,$msg);
			}
		}
		
		return $msg;
	}

}
fuel/app/lang/ja/validation.php
<?php

/**
 * バリデーション時エラーメッセージ定義
 */

return array(
	/**
	 * for Overridden Validation_Error
	 */
	'valid_string_params' => array(
		'alpha'        => 'アルファベット',
		'utf8'         => '全角文字', 
		'numeric'      => '数値',
		'spaces'       => 'スペース', 
		'newlines'     => '改行', 
		'tabs'         => 'タブ', 
		'punctuation'  => 'punctuation', 
		'singlequotes' => 'シングルクオート', 
		'doublequotes' => 'ダブルクオート', 
		'dashes'       => 'ハイフン', 
		'brackets'     => 'brackets', 
		'braces'       => 'braces',
	),
8
7
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
8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?