intl库中的gettext()等效项?

| 我正在寻找一种做i18n和l10n的方法。 我以前用过“ 0”,这很好:我可以简单地用不同的语言创建.mo文件,并且需要翻译的所有内容都使用这种表示法:
echo __(\'string to be translated\');
我知道现在PHP中内置了Intl库,有人告诉我应该使用它而不是
gettext()
。 阅读完php.net上有关Intl的所有内容后,我发现它具有一些不错的功能,例如语言环境处理,字符串比较,数字格式等。 我不知道如何使用Intl库处理常规字符串到字符串的转换。有任何想法吗?     
已邀请:
您将使用gettext。 Intl(如其下的ICU)用于l10n,不加载翻译。     
这个建议不是很真实。 intl函数可与gettext结合使用,而不是替代。 人们将INTL与文本翻译相关联时会想到“ 3”。这些例子表明了这一点。但实际上,它只是类固醇的四分之一。它将数字注入到现有的字符串中。 (我什至不知道在那里的语言环境支持有什么用,因为它只是内部开关。)     
这是我使用intl进行翻译的方式(已在php v。5.3.10和5.4.7上测试): intl.php
namespace Example;
class Intl {

  private $resource;

  public function __construct() {
    $bundle_location = \"./locales\";
    $user_locale = \\Locale::acceptFromHttp( $_SERVER[\'HTTP_ACCEPT_LANGUAGE\'] );
    $this->resource = new \\ResourceBundle( $user_locale, $bundle_location );
  }

 ...
display.php
 use Example\\Intl;

 $intl = new Intl();
 $r = $intl->resource;

 echo $r[\'string_to_be_translated\'];

 ...
资源包 在
locales
目录中,我有我的资源文件: root.res-根语言(英语)
root { 
  string_to_be_translated {String to be translated } 
}
ja.res-日语
ja { 
  string_to_be_translated {\\u5909\\u63DB\\u3055\\u308C\\u308B\\u6587\\u5B57\\u5217 }
}
sp.res-西班牙语
sp { 
  string_to_be_translated {Cadena a ser traducido }
}
(等等)     

要回复问题请先登录注册