
MessageFormatter::create 메서드는 국제화된 메시지를 생성하기 위한 메서드입니다. 플래그를 사용하는 방법은 다음과 같습니다.
- `{0}`, `{1}`, `{2}`와 같은 플래그는 메시지에 대체할 값을 나타냅니다. 예를 들어, `{0} never|{1} once|{2, plural, one {# times} other {# times}}`에서 `{0}`, `{1}`, `{2}`는 대체할 값을 나타냅니다.
- `{2, plural, ...}`은 `{2}`가 1인 경우 `{one {# times}}`을, `{2}`이 0인 경우 `{other {# times}}`을 사용합니다.
- `{# times}`은 대체할 값의 횟수를 나타냅니다.
- `one`과 `other`은 `{2}`이 1인 경우와 `{2}`이 0인 경우에 사용할 메시지를 나타냅니다.
- `{2, plural, one {# times} other {# times}}`을 사용하려면 `{2}`이 1인 경우 `{# times}`을, `{2}`이 0인 경우 `{# times}`을 사용해야 합니다.
예를 들어, `{2, plural, one {# times} other {# times}}`을 사용하려면 `{2}`이 1인 경우 `{# times}`을 `{1}`으로, `{2}`이 0인 경우 `{# times}`을 `{0}`으로 바꿔야 합니다.
따라서, `{2, plural, one {# times} other {# times}}`을 사용하려면 `{2, plural, one {1} other {0}}`으로 바꿔야 합니다.
#hostingforum.kr
php
use SymfonyComponentTranslationMessageFormatter;
$messageFormatter = MessageFormatter::create('en_US', '{0} never|{1} once|{2, plural, one {1} other {0}}');
2025-05-25 04:08