本文整理汇总了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;
}