本文整理匯總了PHP中CRM_Core_I18n::getResourceDir方法的典型用法代碼示例。如果您正苦於以下問題:PHP CRM_Core_I18n::getResourceDir方法的具體用法?PHP CRM_Core_I18n::getResourceDir怎麽用?PHP CRM_Core_I18n::getResourceDir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CRM_Core_I18n
的用法示例。
在下文中一共展示了CRM_Core_I18n::getResourceDir方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: languages
/**
* Return languages available in this instance of CiviCRM.
*
* @param bool $justEnabled
* whether to return all languages or just the enabled ones.
*
* @return array
* Array of code/language name mappings
*/
public static function languages($justEnabled = FALSE)
{
static $all = NULL;
static $enabled = NULL;
if (!$all) {
$all = CRM_Contact_BAO_Contact::buildOptions('preferred_language');
// check which ones are available; add them to $all if not there already
$codes = array();
if (is_dir(CRM_Core_I18n::getResourceDir()) && ($dir = opendir(CRM_Core_I18n::getResourceDir()))) {
while ($filename = readdir($dir)) {
if (preg_match('/^[a-z][a-z]_[A-Z][A-Z]$/', $filename)) {
$codes[] = $filename;
if (!isset($all[$filename])) {
$all[$filename] = $filename;
}
}
}
closedir($dir);
}
// drop the unavailable languages (except en_US)
foreach (array_keys($all) as $code) {
if ($code == 'en_US') {
continue;
}
if (!in_array($code, $codes)) {
unset($all[$code]);
}
}
}
if ($enabled === NULL) {
$config = CRM_Core_Config::singleton();
$enabled = array();
if (isset($config->languageLimit) and $config->languageLimit) {
foreach ($all as $code => $name) {
if (in_array($code, array_keys($config->languageLimit))) {
$enabled[$code] = $name;
}
}
}
}
return $justEnabled ? $enabled : $all;
}
示例2: findLocales
/**
* @return array
*/
public function findLocales()
{
require_once 'CRM/Core/Config.php';
$config = CRM_Core_Config::singleton(FALSE);
$locales = array();
$localeDir = CRM_Core_I18n::getResourceDir();
if (file_exists($localeDir)) {
$locales = preg_grep('/^[a-z][a-z]_[A-Z][A-Z]$/', scandir($localeDir));
}
$localesMask = getenv('CIVICRM_LOCALES');
if (!empty($localesMask)) {
$mask = explode(',', $localesMask);
$locales = array_intersect($locales, $mask);
}
if (!in_array('en_US', $locales)) {
array_unshift($locales, 'en_US');
}
return $locales;
}