Learning More Language
Thursday, April 11, 2024 2:28 PMLanguage
Introduction
-
Locale
에 따른 언어를 출력할 수 있도록 지원하며,getText
방식이 적용되어 있습니다. - 튜닝상점의 경우 언어 설정을 별도 수정하여 사용할 수 없습니다. (추후 지원 예정)
Usage
일반사용 방법
고도몰 컨트롤러 및 컴포넌트에서의 기본적인 사용법은 아래와 같으며 치환코드를 사용하는 경우 1개만 넣을 수 있습니다.
__('오류가 발생하였습니다.');
__('%s 오류가 발생하였습니다.', $erroCode);
치환 문자를 사용해야 하는 경우,
sprintf(__(%s), $sample1, $sample2);
상세사용 방법
아래 함수는 전역함수로 어느 파일에서도 사용할 수 있습니다.
-
$original
: 기본메시지를 선언합니다. -
$plural
: 기본메시지의 복수형을 선언합니다. -
$value
: 복수형 사용을 위한 조건으로 정수형 숫자를 선언합니다. -
$context
: 메시지를 포함하는 위치 정보로 동일 단어를 다르게 사용할 수 있습니다. -
$domain
: 도메인은 언어파일의 범위(영역)를 나타내며 고도몰에서는 파일 이름을 도메인으로 사용하고 있습니다.
기본형 __($original)
#: data/skin/front/food_story/main/index.html:281
msgid "테스트"
msgstr "test"
echo __('테스트');
__e('테스트');
// print
test
test
복수형 n__($original, $plural, $value)
#: data/skin/front/food_story/main/index.html:281
msgid "테스트"
msgid_plural "테스트들"
msgstr[0] "test"
msgstr[1] "tests"
echo n__('테스트', '테스트들', 1);
echo n__('테스트', '테스트들', 2);
// print
test
tests
컨텍스트형 p__($context, $original)
#: data/skin/front/food_story/main/index.html:281
msgctxt "메뉴"
msgid "테스트"
msgstr "menu test"
#: data/skin/front/food_story/main/index.html:281
msgctxt "도구"
msgid "테스트"
msgstr "tool test"
echo p__('메뉴', '테스트');
echo p__('도구', '테스트');
// print
menu test
tool test
도메인형 d__($domain, $original)
// domain1 파일
#: data/skin/front/food_story/main/index.html:281
msgid "테스트"
msgstr "domain1 test"
// domain2 파일
#: data/skin/front/food_story/main/index.html:281
msgid "테스트"
msgstr "domain2 test"
echo d__('도메인1', '테스트');
echo d__('도메인2', '테스트');
// print
domain1 test
domain2 test
도메인 컨텍스트형 dp__($domain, $context, $original)
// domain1 파일
#: data/skin/front/food_story/main/index.html:281
msgctxt "메뉴"
msgid "테스트"
msgstr "domain1 test"
// domain2 파일
#: data/skin/front/food_story/main/index.html:281
msgctxt "도구"
msgid "테스트"
msgstr "domain2 test"
echo dp__('도메인1', '메뉴', '테스트');
echo dp__('도메인1', '도구', '테스트');
echo dp__('도메인2', '메뉴', '테스트');
echo dp__('도메인2', '도구', '테스트');
// print
domain1 menu test
domain1 tool test
domain2 menu test
domain2 tool test
도메인 컨텍스트 복수형 dnp__($domain, $context, $original, $plural, $value)
// domain1 파일
#: data/skin/front/food_story/main/index.html:281
msgctxt "메뉴"
msgid "테스트"
msgid_plural "테스트들"
msgstr[0] "domain1 test"
msgstr[1] "domain1 tests"
// domain2 파일
#: data/skin/front/food_story/main/index.html:281
msgctxt "도구"
msgid "테스트"
msgid_plural "테스트들"
msgstr[0] "domain2 test"
msgstr[1] "domain2 tests"
echo dnp__('도메인1', '메뉴', '테스트', '테스트들', 1);
echo dnp__('도메인1', '도구', '테스트', '테스트들', 2);
echo dnp__('도메인1', '메뉴', '테스트', '테스트들', 1);
echo dnp__('도메인1', '도구', '테스트', '테스트들', 2);
// print
domain1 test
domain1 tests
domain2 test
domain2 tests