라이브러리
[PHP] MessageFormatter::create - 새 메시지 포매터를 구성합니다.
MessageFormatter::create
MessageFormatter::create는 PHP 7.2 버전부터 사용할 수 있는 메서드입니다. 이 메서드는 국제화된 메시지를 생성하기 위해 사용됩니다. 국제화된 메시지는 지역 및 언어에 따라 다르게 표현되는 메시지를 의미합니다.
# 사용법
MessageFormatter::create 메서드는 두 가지 파라미터를 받습니다.
1. locale: 국제화된 메시지를 생성할 지역을 지정합니다. 예를 들어, 'ko_KR'은 한국어를 지정합니다.
2. pattern: 국제화된 메시지를 생성할 패턴을 지정합니다. 패턴은 메시지에 변수를 포함할 수 있습니다.
# 예제
#hostingforum.kr
php
// 한국어 지역을 지정합니다.
$locale = 'ko_KR';
// 국제화된 메시지를 생성할 패턴을 지정합니다.
$pattern = '{0}은 {1}입니다.';
// MessageFormatter::create 메서드를 사용하여 국제화된 메시지를 생성합니다.
$messageFormatter = MessageFormatter::create($locale, $pattern);
// 국제화된 메시지에 변수를 포함합니다.
$variables = array('apple', '사과');
// format 메서드를 사용하여 국제화된 메시지를 생성합니다.
$message = $messageFormatter->format($variables);
// 결과를 출력합니다.
echo $message;
# 결과
#hostingforum.kr
사과은 사과입니다.
# 참고
MessageFormatter::create 메서드는 PHP 7.2 버전부터 사용할 수 있습니다. 이 메서드는 국제화된 메시지를 생성하기 위해 사용됩니다. 지역 및 언어에 따라 다르게 표현되는 메시지를 생성할 수 있습니다.
MessageFormatter::format
MessageFormatter::format 메서드는 MessageFormatter::create 메서드를 사용하여 생성한 국제화된 메시지를 format합니다. 이 메서드는 두 가지 파라미터를 받습니다.
1. variables: 국제화된 메시지에 포함할 변수를 지정합니다.
2. args: 국제화된 메시지에 포함할 변수의 타입을 지정합니다.
# 예제
#hostingforum.kr
php
// 한국어 지역을 지정합니다.
$locale = 'ko_KR';
// 국제화된 메시지를 생성할 패턴을 지정합니다.
$pattern = '{0}은 {1}입니다.';
// MessageFormatter::create 메서드를 사용하여 국제화된 메시지를 생성합니다.
$messageFormatter = MessageFormatter::create($locale, $pattern);
// 국제화된 메시지에 변수를 포함합니다.
$variables = array('apple', '사과');
// format 메서드를 사용하여 국제화된 메시지를 생성합니다.
$message = $messageFormatter->format($variables);
// 결과를 출력합니다.
echo $message;
# 결과
#hostingforum.kr
사과은 사과입니다.
# 참고
MessageFormatter::format 메서드는 MessageFormatter::create 메서드를 사용하여 생성한 국제화된 메시지를 format합니다. 지역 및 언어에 따라 다르게 표현되는 메시지를 생성할 수 있습니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.