gettext 함수
(PHP 4, PHP 5, PHP 7, PHP 8)
gettext — 현재 도메인에서 메시지 조회
설명
gettext(string $message
): string
현재 도메인에서 메시지를 찾습니다.
매개변수
message
- 번역 중인 메시지입니다.
반환 값
번역 테이블에 번역된 문자열이 있으면 번역된 문자열을 반환하고, 찾을 수 없으면 제출된 메시지를 반환합니다.
Examples
예제 #1 gettext()-check
<?php
// Set language to German
putenv('LC_ALL=de_DE');
setlocale(LC_ALL, 'de_DE');
// Specify location of translation tables
bindtextdomain("myPHPApp", "./locale");
// Choose domain
textdomain("myPHPApp");
// Translation is looking for in ./locale/de_DE/LC_MESSAGES/myPHPApp.mo now
// Print a test message
echo gettext("Welcome to My PHP Application");
// Or use the alias _() for gettext()
echo _("Have a nice day");
?>
메모
메모: 이 함수의 별칭으로 밑줄 문자 '_'를 사용할 수 있습니다.
메모: 일부 시스템에서는 언어를 설정하는 것만으로는 충분하지 않으며 현재 로케일을 정의하기 위해 putenv()를 사용해야 합니다.
기타
- setlocale() - 로케일 정보 설정