本文整理汇总了PHP中WT_I18N::translation_adapter方法的典型用法代码示例。如果您正苦于以下问题:PHP WT_I18N::translation_adapter方法的具体用法?PHP WT_I18N::translation_adapter怎么用?PHP WT_I18N::translation_adapter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WT_I18N
的用法示例。
在下文中一共展示了WT_I18N::translation_adapter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* Initialise the translation adapter with a locale setting.
*
* @param string|null $locale If no locale specified, choose one automatically
*
* @return string $string
*/
public static function init($locale = null)
{
global $WT_SESSION;
// The translation libraries only work with a cache.
$cache_options = array('automatic_serialization' => true, 'cache_id_prefix' => md5(WT_SERVER_NAME . WT_SCRIPT_PATH));
if (ini_get('apc.enabled')) {
self::$cache = Zend_Cache::factory('Core', 'Apc', $cache_options, array());
} elseif (WT_File::mkdir(WT_DATA_DIR . 'cache')) {
self::$cache = Zend_Cache::factory('Core', 'File', $cache_options, array('cache_dir' => WT_DATA_DIR . 'cache'));
} else {
self::$cache = Zend_Cache::factory('Core', 'Zend_Cache_Backend_BlackHole', $cache_options, array(), false, true);
}
Zend_Locale::setCache(self::$cache);
Zend_Translate::setCache(self::$cache);
$installed_languages = self::installed_languages();
if (is_null($locale) || !array_key_exists($locale, $installed_languages)) {
// Automatic locale selection.
$locale = WT_Filter::get('lang');
if ($locale && array_key_exists($locale, $installed_languages)) {
// Requested in the URL?
if (Auth::id()) {
Auth::user()->setSetting('language', $locale);
}
} elseif (array_key_exists($WT_SESSION->locale, $installed_languages)) {
// Rembered from a previous visit?
$locale = $WT_SESSION->locale;
} else {
// Browser preference takes priority over gedcom default
if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$prefs = explode(',', str_replace(' ', '', $_SERVER['HTTP_ACCEPT_LANGUAGE']));
} else {
$prefs = array();
}
if (WT_GED_ID) {
// Add the tree’s default language as a low-priority
$locale = get_gedcom_setting(WT_GED_ID, 'LANGUAGE');
$prefs[] = $locale . ';q=0.2';
}
$prefs2 = array();
foreach ($prefs as $pref) {
list($l, $q) = explode(';q=', $pref . ';q=1.0');
$l = preg_replace_callback('/_[a-z][a-z]$/', function ($x) {
return strtoupper($x[0]);
}, str_replace('-', '_', $l));
// en-gb => en_GB
if (array_key_exists($l, $prefs2)) {
$prefs2[$l] = max((double) $q, $prefs2[$l]);
} else {
$prefs2[$l] = (double) $q;
}
}
// Ensure there is a fallback.
if (!array_key_exists('en_US', $prefs2)) {
$prefs2['en_US'] = 0.01;
}
arsort($prefs2);
foreach (array_keys($prefs2) as $pref) {
if (array_key_exists($pref, $installed_languages)) {
$locale = $pref;
break;
}
}
}
}
// Load the translation file
self::$translation_adapter = new Zend_Translate('gettext', WT_ROOT . 'language/' . $locale . '.mo', $locale);
// Deprecated - some custom modules use this to add translations
Zend_Registry::set('Zend_Translate', self::$translation_adapter);
// Load any local user translations
if (is_dir(WT_DATA_DIR . 'language')) {
if (file_exists(WT_DATA_DIR . 'language/' . $locale . '.mo')) {
self::addTranslation(new Zend_Translate('gettext', WT_DATA_DIR . 'language/' . $locale . '.mo', $locale));
}
if (file_exists(WT_DATA_DIR . 'language/' . $locale . '.php')) {
self::addTranslation(new Zend_Translate('array', WT_DATA_DIR . 'language/' . $locale . '.php', $locale));
}
if (file_exists(WT_DATA_DIR . 'language/' . $locale . '.csv')) {
self::addTranslation(new Zend_Translate('csv', WT_DATA_DIR . 'language/' . $locale . '.csv', $locale));
}
}
// Extract language settings from the translation file
global $DATE_FORMAT;
// I18N: This is the format string for full dates. See http://php.net/date for codes
$DATE_FORMAT = self::noop('%j %F %Y');
global $TIME_FORMAT;
// I18N: This is the format string for the time-of-day. See http://php.net/date for codes
$TIME_FORMAT = self::noop('%H:%i:%s');
// Alphabetic sorting sequence (upper-case letters), used by webtrees to sort strings
list(, self::$alphabet_upper) = explode('=', self::noop('ALPHABET_upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ'));
// Alphabetic sorting sequence (lower-case letters), used by webtrees to sort strings
list(, self::$alphabet_lower) = explode('=', self::noop('ALPHABET_lower=abcdefghijklmnopqrstuvwxyz'));
global $WEEK_START;
// I18N: This is the first day of the week on calendars. 0=Sunday, 1=Monday...
//.........这里部分代码省略.........