2024 PHP Conference Japan

ResourceBundle::create

resourcebundle_create

ResourceBundle::__construct

(PHP 5 >= 5.3.2, PHP 7, PHP 8, PECL intl >= 2.0.0)

ResourceBundle::create -- resourcebundle_create -- ResourceBundle::__construct建立資源包

描述

物件導向風格 (方法)

public static ResourceBundle::create(?string $locale, ?string $bundle, bool $fallback = true): ?ResourceBundle

程序式風格

resourcebundle_create(?string $locale, ?string $bundle, bool $fallback = true): ?ResourceBundle

物件導向風格(建構子)

public ResourceBundle::__construct(?string $locale, ?string $bundle, bool $fallback = true)

建立一個資源包。

參數

locale

應該載入資源的地區設定(地區設定名稱,例如 en_CA)。

bundle

儲存資料的目錄或 .dat 檔案的名稱。

fallback

地區設定是否應該完全相符,或者允許回退到父地區設定。

回傳值

傳回 ResourceBundle 物件,或錯誤時傳回 null

範例

範例 #1 resourcebundle_create() 範例

<?php
$r
= resourcebundle_create( 'es', "/usr/share/data/myapp");
echo
$r['teststring'];
?>

範例 #2 ResourceBundle::create() 範例

<?php
$r
= ResourceBundle::create( 'es', "/usr/share/data/myapp");
echo
$r['teststring'];
?>

以上範例會輸出

¡Hola, mundo!

另請參閱

新增註解

使用者貢獻的註解 3 則註解

mail at dasprids dot de
10 年前
由於我花了超過 4 個小時挖掘 libicu 原始碼才找到答案,我想在這裡發布是個好主意。要存取預設「語系」資料以外的其他資料(透過傳遞 NULL 作為 $bundlename 取得),您可以使用以下有點神奇的字串來取得其他資源包

ICUDATA-curr
ICUDATA-lang
ICUDATA-region
ICUDATA-zone
匿名
5 年前
根據您要載入的資料,您可能需要傳遞 'root' 或其他不同的值作為 $locale。
以下是一些範例及其對應載入檔案的連結列表

ResourceBundle::create('de', 'ICUDATA-brkitr', false)
https://github.com/unicode-org/icu/blob/release-65-1/icu4c/source/data/brkitr/de.txt

ResourceBundle::create('root', 'ICUDATA-curr', false)
https://github.com/unicode-org/icu/blob/release-65-1/icu4c/source/data/curr/root.txt

ResourceBundle::create('root', 'ICUDATA-translit', false)
https://github.com/unicode-org/icu/blob/release-65-1/icu4c/source/data/translit/root.txt

ResourceBundle::create('likelySubtags', 'ICUDATA', false)
https://github.com/unicode-org/icu/blob/release-65-1/icu4c/source/data/misc/likelySubtags.txt
mail at dasprids dot de
10 年前
要取得 libicu 提供的資源包,您可以傳遞 "null" 作為 $bundlename。
To Top