
MessageFormatter::create 메서드는 MessageFormatter 인스턴스를 생성하기 위해 사용됩니다. 이 메서드는 두 개의 파라미터를 받습니다.
1. 첫 번째 파라미터는 locale, 이는 메시지를 형식화할 지역 설정입니다. 예를 들어, 'ko_KR'은 한국어를 의미하고, 'en_US'은 미국 영어를 의미합니다.
2. 두 번째 파라미터는 pattern, 이는 메시지를 형식화할 패턴입니다. 이 패턴은 MessageFormat 클래스의 format 메서드에서 사용됩니다.
MessageFormatter::create 메서드를 사용하는 예제는 다음과 같습니다.
#hostingforum.kr
php
$messageFormatter = MessageFormatter::create('ko_KR', '{0}은 {1}의 {2}입니다.');
$message = $messageFormatter->format('apple', '사과', '색상');
echo $message; // apple은 사과의 색상입니다.
위 예제에서, 'ko_KR'은 한국어 지역 설정을 의미하고, '{0}은 {1}의 {2}입니다.'는 패턴을 의미합니다. 이 패턴은 MessageFormat 클래스의 format 메서드에서 사용됩니다.
2025-03-17 17:42