本文整理汇总了PHP中bindtextdomain函数的典型用法代码示例。如果您正苦于以下问题:PHP bindtextdomain函数的具体用法?PHP bindtextdomain怎么用?PHP bindtextdomain使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bindtextdomain函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize_domain
public function initialize_domain($domain, $path)
{
if (!isset($this->domains[$domain])) {
bindtextdomain($domain, $path);
$this->domains[$domain] = $path;
}
}
示例2: set_language
function set_language()
{
global $amp_conf, $db;
$nt = notifications::create($db);
if (extension_loaded('gettext')) {
$nt->delete('core', 'GETTEXT');
if (php_sapi_name() !== 'cli') {
if (empty($_COOKIE['lang']) || !preg_match('/^[\\w\\._@-]+$/', $_COOKIE['lang'], $matches)) {
$lang = $amp_conf['UIDEFAULTLANG'] ? $amp_conf['UIDEFAULTLANG'] : 'en_US';
if (empty($_COOKIE['lang'])) {
setcookie("lang", $lang);
}
} else {
preg_match('/^([\\w\\._@-]+)$/', $_COOKIE['lang'], $matches);
$lang = !empty($matches[1]) ? $matches[1] : 'en_US';
}
$_COOKIE['lang'] = $lang;
} else {
$lang = $amp_conf['UIDEFAULTLANG'] ? $amp_conf['UIDEFAULTLANG'] : 'en_US';
}
putenv('LC_ALL=' . $lang);
putenv('LANG=' . $lang);
putenv('LANGUAGE=' . $lang);
setlocale(LC_ALL, $lang);
bindtextdomain('amp', $amp_conf['AMPWEBROOT'] . '/admin/i18n');
bind_textdomain_codeset('amp', 'utf8');
textdomain('amp');
return $lang;
}
$nt->add_warning('core', 'GETTEXT', _("Gettext is not installed"), _("Please install gettext so that the PBX can properly translate itself"), 'https://www.gnu.org/software/gettext/');
return 'en_US';
}
示例3: before
function before($route)
{
$lang_mapping = array('fr' => 'fr_FR');
if (!isset($_SESSION['locale'])) {
$locale = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
$_SESSION['locale'] = strtolower(substr(chop($locale[0]), 0, 2));
}
$lang = $_SESSION['locale'];
// Convert simple language code into full language code
if (array_key_exists($lang, $lang_mapping)) {
$lang = $lang_mapping[$lang];
}
$lang = "{$lang}.utf8";
$textdomain = "localization";
putenv("LANGUAGE={$lang}");
putenv("LANG={$lang}");
putenv("LC_ALL={$lang}");
putenv("LC_MESSAGES={$lang}");
setlocale(LC_ALL, $lang);
setlocale(LC_CTYPE, $lang);
$locales_dir = dirname(__FILE__) . '/i18n';
bindtextdomain($textdomain, $locales_dir);
bind_textdomain_codeset($textdomain, 'UTF-8');
textdomain($textdomain);
set('locale', $lang);
}
示例4: init_gettext
/**
* Initialise our use of Gettext
*/
function init_gettext($domain, $location)
{
bindtextdomain($domain, $location);
$codeset = bind_textdomain_codeset($domain, "UTF-8");
textdomain($domain);
dbg_error_log("I18N", "Bound domain =%s= to location =%s= using character set =%s=", $domain, $location, $codeset);
}
示例5: set
/**
* Sets i18n locale language
*
* sets the language for i18n php gettext module
* (gettext has to be enabled in the php.ini)
*
*/
function set()
{
if (extension_loaded('gettext')) {
// try and find the default locale
$default_lang = preg_replace('/-/', '_', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
$locale = 'en_US';
$locale_dir = "./locale";
$directories = getdirectories($locale_dir, "");
foreach ($directories as $directory) {
$buf = substr($directory, strlen($locale_dir) + 1, strlen($directory) - strlen($locale_dir));
if (preg_match("/" . $buf . "/i", $default_lang)) {
$locale = $buf;
break;
}
}
// set locale
$language = isset($_COOKIE['ari_lang']) ? $_COOKIE['ari_lang'] : $locale;
putenv("LANG={$language}");
putenv("LANGUAGE={$language}");
setlocale(LC_MESSAGES, $language);
bindtextdomain('ari', './locale');
bind_textdomain_codeset('ari', 'UTF-8');
textdomain('ari');
} else {
function _($str)
{
return $str;
}
}
}
示例6: bindTextDomain
/**
* Set the path for a domain.
*
* @param string $domain
* @param string $path
* @return string
*/
public function bindTextDomain($domain, $path)
{
if ($this->driver->hasLocaleAndFunction('bindtextdomain')) {
return bindtextdomain($domain, $path);
}
return $this->driver->bindTextDomain($domain, $path);
}
示例7: localization_setup
function localization_setup()
{
global $lang, $domain, $encoding, $available_locales, $preferred_lang;
// Choose a default language based on the client's HTTP headers.
// TODO: Replace HTTP::negotiateLanguage with something less buggy.
// (See http://www.dracos.co.uk/web/php/HTTP/ for details.)
$supported = $available_locales;
$preferred_lang = HTTP::negotiateLanguage($supported, $lang);
if ($preferred_lang) {
$lang = $preferred_lang;
}
// Override the default if the user has an explicit cookie or query string.
$force_lang = get_requested_lang();
if ($force_lang) {
$lang = $force_lang;
}
if ($available_locales[$lang]) {
// Set the locale.
$locale = $available_locales[$lang][0];
setlocale(LC_ALL, $locale);
// Find the locale directory.
$path_parts = pathinfo(__FILE__);
$this_dir = $path_parts["dirname"];
bindtextdomain($domain, "{$this_dir}/../locale");
// Set up gettext message localization.
textdomain($domain);
bind_textdomain_codeset($domain, $encoding);
}
// Tell clients to cache different languages separately.
header("Vary: Accept-Language");
}
示例8: package
static function package($name, $path = null)
{
if ($path !== null) {
bindtextdomain($name, $GLOBALS['_lang']->path . $path);
}
textdomain($name);
}
示例9: setDomain
/** Set domain name.
*
* @param string $dir Directory path, where to find domain. In this directory current locale named subdirectory will be searched.
* @param string $domain Domain name - filename without MO extension.
* @param string $codeset Domain file codeset.
*
* @return $this
*/
public final function setDomain($dir, $domain, $codeset = 'UTF-8')
{
bindtextdomain($domain, $dir);
bind_textdomain_codeset($domain, $codeset);
$this->domains[] = $domain;
return $this;
}
示例10: __construct
public function __construct($lang = 'en_EN', $domain = 'default')
{
/* ./locale/en_EN/LC_MESSAGES/default.po */
$fnMO = dirname(__FILE__) . '/locale/' . $lang . '/LC_MESSAGES/' . $domain . '.mo';
if (!file_exists($fnMO)) {
$fnPO = substr($fnMO, 0, -2) . 'po';
if (file_exists($fnPO) && is_readable($fnPO)) {
$this->_moConverter($fnPO);
}
}
@putenv('LC_ALL=' . $lang);
@setlocale(LC_ALL, $lang);
if (function_exists('bindtextdomain')) {
bindtextdomain($domain, dirname(__FILE__) . '/locale');
}
if (function_exists('bind_textdomain_codeset')) {
bind_textdomain_codeset($domain, 'UTF-8');
}
if (function_exists('textdomain')) {
textdomain($domain);
}
$this->_defaultFunction = false;
$this->_cache = array();
if (function_exists('gettext')) {
$this->_defaultFunction = true;
} else {
$_tmp = $this->_moRead($fnMO, $lang);
if (is_array($_tmp)) {
$this->_cache = $_tmp[$lang];
}
unset($_tmp);
}
}
示例11: __construct
/**
* Build a new reporter html render
*/
protected function __construct()
{
putenv('LC_ALL=' . self::$lang);
setlocale(LC_ALL, self::$lang);
bindtextdomain($this->domain, self::$i18nPath);
textdomain($this->domain);
}
示例12: setUp
protected function setUp()
{
// override bootstrap settings
bindtextdomain("default", E7_PATH . "/tests/i18n");
textdomain("default");
bind_textdomain_codeset("default", 'UTF-8');
}
示例13: smarty_function_locale
/**
* ------------------------------------------------------------------------- *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
* ------------------------------------------------------------------------- *
*
* @package smarty-gettext
* @link https://github.com/smarty-gettext/smarty-gettext/
* @author Karlheinz Toni <karlheinz.toni@gmail.com>
* @author Boleslaw Tekielski <bolek@gvault13.pl>
* @author Elan Ruusamäe <glen@delfi.ee>
* @copyright 2012 Karlheinz Toni
* @copyright 2015 Boleslaw Tekielski
* @copyright 2015 Elan Ruusamäe
*/
function smarty_function_locale($params, &$smarty)
{
static $stack;
// init stack as array
if ($stack === null) {
$stack = array();
}
$path = null;
$template_dirs = method_exists($smarty, 'getTemplateDir') ? $smarty->getTemplateDir() : $smarty->template_dir;
$path_param = isset($params['path']) ? $params['path'] : '';
$domain = isset($params['domain']) ? $params['domain'] : 'messages';
$stack_operation = isset($params['stack']) ? $params['stack'] : 'push';
foreach ((array) $template_dirs as $template_dir) {
$path = $template_dir . $path_param;
if (is_dir($path)) {
break;
}
}
if (!$path && $stack_operation != 'pop') {
trigger_error("Directory for locales not found (path='{$path_param}')", E_USER_ERROR);
}
if ($stack_operation == 'push') {
$stack[] = array($domain, $path);
} elseif ($stack_operation == 'pop') {
if (count($stack) > 1) {
array_pop($stack);
}
list($domain, $path) = end($stack);
} else {
trigger_error("Unknown stack operation '{$stack_operation}'", E_USER_ERROR);
}
bind_textdomain_codeset($domain, 'UTF-8');
bindtextdomain($domain, $path);
textdomain($domain);
}
示例14: init
private function init()
{
Tools::initPhp();
if (isset($_SESSION['poche_user']) && $_SESSION['poche_user'] != array()) {
$this->user = $_SESSION['poche_user'];
} else {
# fake user, just for install & login screens
$this->user = new User();
$this->user->setConfig($this->getDefaultConfig());
}
# l10n
$language = $this->user->getConfigValue('language');
@putenv('LC_ALL=' . $language);
setlocale(LC_ALL, $language);
bindtextdomain($language, LOCALE);
textdomain($language);
# Pagination
$this->pagination = new Paginator($this->user->getConfigValue('pager'), 'p');
# Set up theme
$themeDirectory = $this->user->getConfigValue('theme');
if ($themeDirectory === false) {
$themeDirectory = DEFAULT_THEME;
}
$this->currentTheme = $themeDirectory;
# Set up language
$languageDirectory = $this->user->getConfigValue('language');
if ($languageDirectory === false) {
$languageDirectory = DEFAULT_THEME;
}
$this->currentLanguage = $languageDirectory;
}
示例15: bindTextDomain
/**
* {@inheritdoc}
*/
public function bindTextDomain($textDomain, $codeSet = null)
{
$this->bendTextDomains[$textDomain] = array();
$textDomainDir = bindtextdomain($textDomain, $this->directory);
$translationFileDir = $textDomainDir . DIRECTORY_SEPARATOR . StringUtils::beforeFirst(setlocale(LC_MESSAGES, '0'), '.') . DIRECTORY_SEPARATOR . 'LC_MESSAGES';
$moFilePath = $translationFileDir . DIRECTORY_SEPARATOR . $textDomain . '.mo';
$poFilePath = $translationFileDir . DIRECTORY_SEPARATOR . $textDomain . '.po';
if (file_exists($moFilePath) === true) {
$this->bendTextDomains[$textDomain]['file_path'] = $moFilePath;
$this->bendTextDomains[$textDomain]['type'] = 'mo';
} elseif (file_exists($poFilePath) === true && $this->poParserInterface instanceof PoParserInterface === true) {
$this->bendTextDomains[$textDomain]['file_path'] = $poFilePath;
$this->bendTextDomains[$textDomain]['type'] = 'po';
$this->bendTextDomains[$textDomain]['plural_expr'] = false;
$this->bendTextDomains[$textDomain]['entries'] = $this->poParserInterface->extract($poFilePath);
$this->bendTextDomains[$textDomain]['plural_expr'] = '$' . $this->defaultPluralRule . ';';
// Default plural rule
$this->bendTextDomains[$textDomain]['plurals'] = 2;
if (isset($this->bendTextDomains[$textDomain]['entries']['']) === true) {
foreach ($this->bendTextDomains[$textDomain]['entries']['']['msgstr'] as $meta) {
if (preg_match('/Plural-Forms:\\s+nplurals=(\\d+);\\s+(plural=[^;]+)/', $meta, $matches) === 0) {
continue;
}
$this->bendTextDomains[$textDomain]['plurals'] = (int) $matches[1];
$this->bendTextDomains[$textDomain]['plural_expr'] = '$' . $matches[2] . ';';
}
}
} else {
return;
}
$textDomainCodeSet = $codeSet !== null ? $codeSet : $this->defaultCodeSet;
if (bind_textdomain_codeset($textDomain, $textDomainCodeSet) === $textDomainCodeSet) {
$this->bendTextDomains[$textDomain]['code_set'] = $textDomainCodeSet;
}
}