文字

The ResourceBundle class

(PHP >= 5.3.2, PECL intl >= 2.0.0)

简介

Localized software products often require sets of data that are to be customized depending on current locale, e.g.: messages, labels, formatting patterns. ICU resource mechanism allows to define sets of resources that the application can load on locale basis, while accessing them in unified locale-independent fashion.

This class implements access to ICU resource data files. These files are binary data arrays which ICU uses to store the localized data.

ICU resource bundle can hold simple resources and complex resources. Complex resources are containers which can be either integer-indexed or string-indexed (just like PHP arrays). Simple resources can be of the following types: string, integer, binary data field or integer array.

ResourceBundle supports direct access to the data through array access pattern and iteration via foreach, as well as access via class methods. The result will be PHP value for simple resources and ResourceBundle object for complex ones. All resources are read-only.

类摘要

ResourceBundle {
public __construct ( string $locale , string $bundlename [, bool $fallback ] )
public int count ( void )
public static ResourceBundle create ( string $locale , string $bundlename [, bool $fallback ] )
public int getErrorCode ( void )
public string getErrorMessage ( void )
public mixed get ( string|int $index )
public array getLocales ( string $bundlename )
}

参见

  • »  ICU Resource Management
  • » ICU Data

Table of Contents

  • ResourceBundle::count — Get number of elements in the bundle
  • ResourceBundle::create — Create a resource bundle
  • ResourceBundle::getErrorCode — Get bundle's last error code.
  • ResourceBundle::getErrorMessage — Get bundle's last error message.
  • ResourceBundle::get — Get data from the bundle
  • ResourceBundle::getLocales — Get supported locales

用户评论:

[#1] maiseralves at gmail dot com [2011-05-19 13:03:46]

<?php


//recursive function to list a resource bundle file structure using a ResourceBundle Object ( ) reference 
function t($rb) {
    foreach(
$rb as $k => $v) {
        if(
is_object($v)) {
            
print_r($v);
            
var_dump($k);
            
t($v);
        } else {
            
var_dump($k " " $v);
        }
    }
}
//open root.res from folder locale
$rb = new ResourceBundle('root'"./locale");

t($rb);//call the function


?>

上一篇: 下一篇: