本文整理汇总了PHP中_setlocale函数的典型用法代码示例。如果您正苦于以下问题:PHP _setlocale函数的具体用法?PHP _setlocale怎么用?PHP _setlocale使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_setlocale函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: startup_gettext
function startup_gettext()
{
# Get locale from Accept-Language header
$lang = al2gt(array_keys(get_translations()), "text/html");
if (defined('_TRANSLATION_OVERRIDE_DEFAULT')) {
$lang = _TRANSLATION_OVERRIDE_DEFAULT;
}
/* In login action of mobile version */
if ($_POST["language"] && defined('MOBILE_VERSION')) {
$lang = $_POST["language"];
} else {
if ($_SESSION["language"] && $_SESSION["language"] != "auto") {
$lang = $_SESSION["language"];
}
}
if ($lang) {
if (defined('LC_MESSAGES')) {
_setlocale(LC_MESSAGES, $lang);
} else {
if (defined('LC_ALL')) {
_setlocale(LC_ALL, $lang);
}
}
if (defined('MOBILE_VERSION')) {
_bindtextdomain("messages", "../locale");
} else {
_bindtextdomain("messages", "locale");
}
_textdomain("messages");
_bind_textdomain_codeset("messages", "UTF-8");
}
}
示例2: _setlocale
/**
* Sets a requested locale, if needed emulates it.
*/
function _setlocale($category, $locale)
{
global $CURRENTLOCALE, $EMULATEGETTEXT;
if ($locale === 0) {
// use === to differentiate between string "0"
if ($CURRENTLOCALE != '') {
return $CURRENTLOCALE;
} else {
// obey LANG variable, maybe extend to support all of LC_* vars
// even if we tried to read locale without setting it first
return _setlocale($category, $CURRENTLOCALE);
}
} else {
$ret = 0;
if (function_exists('setlocale')) {
// I don't know if this ever happens ;)
$ret = setlocale(LC_ALL, $locale);
}
if ($ret and $locale == '' or $ret == $locale) {
$EMULATEGETTEXT = 0;
$CURRENTLOCALE = $ret;
} else {
if ($locale == '') {
// emulate variable support
$CURRENTLOCALE = getenv('LANG');
} else {
$CURRENTLOCALE = $locale;
}
$EMULATEGETTEXT = 1;
}
return $CURRENTLOCALE;
}
}
示例3: startup_gettext
function startup_gettext()
{
# Get locale from Accept-Language header
$lang = al2gt(array_keys(get_translations()), "text/html");
if (defined('_TRANSLATION_OVERRIDE_DEFAULT')) {
$lang = _TRANSLATION_OVERRIDE_DEFAULT;
}
if ($_SESSION["uid"] && get_schema_version() >= 120) {
$pref_lang = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
if ($pref_lang && $pref_lang != 'auto') {
$lang = $pref_lang;
}
}
if ($lang) {
if (defined('LC_MESSAGES')) {
_setlocale(LC_MESSAGES, $lang);
} else {
if (defined('LC_ALL')) {
_setlocale(LC_ALL, $lang);
}
}
_bindtextdomain("messages", "locale");
_textdomain("messages");
_bind_textdomain_codeset("messages", "UTF-8");
}
}
示例4: setUp
public function setUp()
{
MoTranslator\Loader::loadFunctions();
_setlocale(0, 'cs');
_textdomain('phpmyadmin');
_bindtextdomain('phpmyadmin', __DIR__ . '/data/locale/');
_bind_textdomain_codeset('phpmyadmin', 'UTF-8');
}
示例5: test_setlocale_emulation
public function test_setlocale_emulation()
{
putenv("LC_ALL=");
// If we set it to a non-existent locale, it still works, but uses
// emulation.
_setlocale(LC_MESSAGES, "xxx_XXX");
$this->assertEquals('xxx_XXX', _setlocale(LC_MESSAGES, 0));
$this->assertEquals(1, locale_emulation());
}
示例6: changeLocale
function changeLocale($newlocale)
{
global $CURRENTLOCALE, $EMULATEGETTEXT, $text_domains;
$CURRENTLOCALE = $newlocale;
$EMULATEGETTEXT = 1;
_textdomain('kusaba');
_setlocale(LC_ALL, $newlocale);
_bindtextdomain('kusaba', KU_ROOTDIR . 'inc/lang', $newlocale);
_bind_textdomain_codeset('kusaba', KU_CHARSET);
}
示例7: testGettext
/**
* Test for setting and parsing locales
*
* @param string $locale locale name
*
* @return void
*
* @group large
* @dataProvider listLocales
*/
public function testGettext($locale)
{
/* We should be able to set the language */
$this->assertTrue(PMA_langSet($locale));
/* Bind locales */
_setlocale(LC_MESSAGES, $GLOBALS['lang']);
_bind_textdomain_codeset('phpmyadmin', 'UTF-8');
_textdomain('phpmyadmin');
/* Grab some texts */
$this->assertContains('%s', _ngettext('%s table', '%s tables', 10));
$this->assertContains('%s', _ngettext('%s table', '%s tables', 1));
}
示例8: __construct
public function __construct($language_locale_uri)
{
$this->language_locale_uri = $language_locale_uri;
// include php-gettext.php file.
// @link https://launchpad.net/php-gettext
if (is_file(SYSTEM_PATH . DS . 'Packages' . DS . 'php-gettext' . DS . 'php-gettext.php')) {
require_once SYSTEM_PATH . DS . 'Packages' . DS . 'php-gettext' . DS . 'php-gettext.php';
}
if (function_exists('_setlocale')) {
_setlocale(LC_MESSAGES, $language_locale_uri);
}
}
示例9: test_setlocale
public function test_setlocale()
{
// _setlocale defaults to a locale name from environment variable LANG.
putenv("LANG=sr_RS");
$this->assertEquals('sr_RS', _setlocale(LC_MESSAGES, 0));
// For an existing locale, it never needs emulation.
putenv("LANG=C");
_setlocale(LC_MESSAGES, "");
$this->assertEquals(0, locale_emulation());
// If we set it to a non-existent locale, it still works, but uses
// emulation.
_setlocale(LC_MESSAGES, "xxx_XXX");
$this->assertEquals('xxx_XXX', _setlocale(LC_MESSAGES, 0));
$this->assertEquals(1, locale_emulation());
}
示例10: init_locale
function init_locale($locale, $error = 'error')
{
if (_setlocale(LC_ALL, $locale) === false) {
$error('The specified locale (' . $locale . ') does not exist on your platform!');
}
if (extension_loaded('gettext')) {
bindtextdomain('tinyboard', './inc/locale');
bind_textdomain_codeset('tinyboard', 'UTF-8');
textdomain('tinyboard');
} else {
_bindtextdomain('tinyboard', './inc/locale');
_bind_textdomain_codeset('tinyboard', 'UTF-8');
_textdomain('tinyboard');
}
}
示例11: init_locale
function init_locale($locale, $error = 'error')
{
if ($locale === 'en') {
$locale = 'en_US.utf8';
}
if (extension_loaded('gettext')) {
setlocale(LC_ALL, $locale);
bindtextdomain('tinyboard', './inc/locale');
bind_textdomain_codeset('tinyboard', 'UTF-8');
textdomain('tinyboard');
} else {
_setlocale(LC_ALL, $locale);
_bindtextdomain('tinyboard', './inc/locale');
_bind_textdomain_codeset('tinyboard', 'UTF-8');
_textdomain('tinyboard');
}
}
示例12: T_setlocale
function T_setlocale($category, $locale)
{
return _setlocale($category, $locale);
}
示例13: loadConfig
//.........这里部分代码省略.........
if (!isset($config['referer_match'])) {
if (isset($_SERVER['HTTP_HOST'])) {
$config['referer_match'] = '/^' . (preg_match('@^https?://@', $config['root']) ? '' : 'https?:\\/\\/' . $_SERVER['HTTP_HOST']) . preg_quote($config['root'], '/') . '(' . str_replace('%s', $config['board_regex'], preg_quote($config['board_path'], '/')) . '(' . preg_quote($config['file_index'], '/') . '|' . str_replace('%d', '\\d+', preg_quote($config['file_page'])) . ')?' . '|' . str_replace('%s', $config['board_regex'], preg_quote($config['board_path'], '/')) . preg_quote($config['dir']['res'], '/') . str_replace('%d', '\\d+', preg_quote($config['file_page'], '/')) . '|' . preg_quote($config['file_mod'], '/') . '\\?\\/.+' . ')([#?](.+)?)?$/ui';
} else {
// CLI mode
$config['referer_match'] = '//';
}
}
if (!isset($config['cookies']['path'])) {
$config['cookies']['path'] =& $config['root'];
}
if (!isset($config['dir']['static'])) {
$config['dir']['static'] = $config['root'] . 'static/';
}
if (!isset($config['image_sticky'])) {
$config['image_sticky'] = $config['dir']['static'] . 'sticky.gif';
}
if (!isset($config['image_locked'])) {
$config['image_locked'] = $config['dir']['static'] . 'locked.gif';
}
if (!isset($config['image_bumplocked'])) {
$config['image_bumplocked'] = $config['dir']['static'] . 'sage.gif';
}
if (!isset($config['image_deleted'])) {
$config['image_deleted'] = $config['dir']['static'] . 'deleted.png';
}
if (!isset($config['uri_thumb'])) {
$config['uri_thumb'] = $config['root'] . $board['dir'] . $config['dir']['thumb'];
} elseif (isset($board['dir'])) {
$config['uri_thumb'] = sprintf($config['uri_thumb'], $board['dir']);
}
if (!isset($config['uri_img'])) {
$config['uri_img'] = $config['root'] . $board['dir'] . $config['dir']['img'];
} elseif (isset($board['dir'])) {
$config['uri_img'] = sprintf($config['uri_img'], $board['dir']);
}
if (!isset($config['uri_stylesheets'])) {
$config['uri_stylesheets'] = $config['root'] . 'stylesheets/';
}
if (!isset($config['url_stylesheet'])) {
$config['url_stylesheet'] = $config['uri_stylesheets'] . 'style.css';
}
if (!isset($config['url_javascript'])) {
$config['url_javascript'] = $config['root'] . $config['file_script'];
}
if (!isset($config['additional_javascript_url'])) {
$config['additional_javascript_url'] = $config['root'];
}
if (!isset($config['uri_flags'])) {
$config['uri_flags'] = $config['root'] . 'static/flags/%s.png';
}
if ($config['root_file']) {
chdir($config['root_file']);
}
if ($config['verbose_errors']) {
set_error_handler('verbose_error_handler');
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('html_errors', false);
}
// Keep the original address to properly comply with other board configurations
if (!isset($__ip)) {
$__ip = $_SERVER['REMOTE_ADDR'];
}
// ::ffff:0.0.0.0
if (preg_match('/^\\:\\:(ffff\\:)?(\\d+\\.\\d+\\.\\d+\\.\\d+)$/', $__ip, $m)) {
$_SERVER['REMOTE_ADDR'] = $m[2];
}
if ($config['locale'] != 'en') {
if (_setlocale(LC_ALL, $config['locale']) === false) {
$error('The specified locale (' . $config['locale'] . ') does not exist on your platform!');
}
if (extension_loaded('gettext')) {
bindtextdomain('tinyboard', './inc/locale');
bind_textdomain_codeset('tinyboard', 'UTF-8');
textdomain('tinyboard');
} else {
_bindtextdomain('tinyboard', './inc/locale');
_bind_textdomain_codeset('tinyboard', 'UTF-8');
_textdomain('tinyboard');
}
}
if ($config['syslog']) {
openlog('tinyboard', LOG_ODELAY, LOG_SYSLOG);
}
// open a connection to sysem logger
if ($config['recaptcha']) {
require_once 'inc/lib/recaptcha/recaptchalib.php';
}
if ($config['cache']['enabled']) {
require_once 'inc/cache.php';
}
event('load-config');
if ($config['debug']) {
if (!isset($debug)) {
$debug = array('sql' => array(), 'exec' => array(), 'purge' => array(), 'cached' => array(), 'write' => array(), 'time' => array('db_queries' => 0, 'exec' => 0), 'start' => $microtime_start, 'start_debug' => microtime(true));
$debug['start'] = $microtime_start;
}
}
}
示例14: dirname
<?php
require_once 'config.php';
$locale = LANG;
$textdomain = "multi_lang";
$locales_dir = dirname(__FILE__) . '/lang';
if (isset($_GET['lang']) && !empty($_GET['lang'])) {
$locale = $_GET['lang'];
}
putenv('LANGUAGE=' . $locale);
putenv('LANG=' . $locale);
putenv('LC_ALL=' . $locale);
putenv('LC_MESSAGES=' . $locale);
require_once 'lib/gettext.inc';
_setlocale(LC_ALL, $locale);
_setlocale(LC_CTYPE, $locale);
_bindtextdomain($textdomain, $locales_dir);
_bind_textdomain_codeset($textdomain, 'UTF-8');
_textdomain($textdomain);
/*
* This function is an helper that should be
* used to avoid some repetitions. Use "_e"
* instead of "echo __".
*/
function _e($string)
{
echo __($string);
}
示例15: _setlocale
/**
* Sets the defined locale
*
* @param string $category The category of the locale to set
* @param mixed $locale The locale, or an array of locales to try and set
* @access public
*/
function _setlocale($category, $locale)
{
if (version_compare(PHP_VERSION, '4.3', '<')) {
if (is_array($locale)) {
foreach ($locale as $l) {
if (($result = _setlocale($category, $l)) !== false) {
return $result;
}
}
return false;
} else {
return _setlocale($category, $locale);
}
} else {
return _setlocale($category, $locale);
}
}