라이브러리

[PHP] ResourceBundle::create - 리소스 번들 생성




PHP에서 ResourceBundle::create 사용하기


PHP의 `ResourceBundle` 클래스는 국제화와 지역화에 사용되는 클래스입니다. 이 클래스를 사용하여 지역화된 리소스를 관리할 수 있습니다. `ResourceBundle::create` 메서드는 새로운 `ResourceBundle` 객체를 생성하는 메서드입니다.

# ResourceBundle::create 메서드


`ResourceBundle::create` 메서드는 다음과 같은 형태로 사용할 수 있습니다.

#hostingforum.kr
php

ResourceBundle::create($key, $category, $locale, $directory)



* `$key`: 리소스 키입니다.
* `$category`: 리소스 카테고리입니다.
* `$locale`: 사용할 지역입니다.
* `$directory`: 리소스 파일이 저장된 디렉토리입니다.

# 예제


다음 예제에서는 `ResourceBundle::create` 메서드를 사용하여 지역화된 리소스를 관리하는 방법을 보여줍니다.

#hostingforum.kr
php

// 리소스 파일을 저장할 디렉토리

$directory = __DIR__ . '/resources';



// 지역

$locale = 'ko_KR';



// 리소스 카테고리

$category = 'messages';



// 리소스 키

$key = 'hello';



// ResourceBundle::create 메서드를 사용하여 ResourceBundle 객체를 생성

$bundle = ResourceBundle::create($key, $category, $locale, $directory);



// ResourceBundle 객체를 사용하여 지역화된 리소스를 가져옵니다.

$message = $bundle->getString($key);



// 결과를 출력합니다.

echo $message;



# 리소스 파일


리소스 파일은 다음과 같은 형태로 저장됩니다.

#hostingforum.kr
php

// messages.properties (en_US)

hello=Hello



// messages.properties (ko_KR)

hello=안녕하세요



# 결과


이 예제를 실행하면 다음과 같은 결과가 출력됩니다.

#hostingforum.kr


안녕하세요



이 예제에서는 `ResourceBundle::create` 메서드를 사용하여 지역화된 리소스를 관리하는 방법을 보여줍니다. 지역화된 리소스를 관리하기 위해 `ResourceBundle` 클래스를 사용할 수 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 273 페이지

검색

게시물 검색