本文整理汇总了PHP中DevblocksPlatform::getLocale方法的典型用法代码示例。如果您正苦于以下问题:PHP DevblocksPlatform::getLocale方法的具体用法?PHP DevblocksPlatform::getLocale怎么用?PHP DevblocksPlatform::getLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DevblocksPlatform
的用法示例。
在下文中一共展示了DevblocksPlatform::getLocale方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTranslationService
/**
* @return _DevblocksTranslationManager
*/
static function getTranslationService()
{
static $languages = array();
$locale = DevblocksPlatform::getLocale();
// Registry
if (isset($languages[$locale])) {
return $languages[$locale];
}
$cache = self::getCacheService();
if (null === ($map = $cache->load(self::CACHE_TAG_TRANSLATIONS . '_' . $locale))) {
/* @var $cache _DevblocksCacheManager */
$map = array();
$map_en = DAO_Translation::getMapByLang('en_US');
if (0 != strcasecmp('en_US', $locale)) {
$map_loc = DAO_Translation::getMapByLang($locale);
}
// Loop through the English string objects
if (is_array($map_en)) {
foreach ($map_en as $string_id => $obj_string_en) {
$string = '';
// If we have a locale to check
if (isset($map_loc) && is_array($map_loc)) {
@($obj_string_loc = $map_loc[$string_id]);
@($string = !empty($obj_string_loc->string_override) ? $obj_string_loc->string_override : $obj_string_loc->string_default);
}
// If we didn't hit, load the English default
if (empty($string)) {
@($string = !empty($obj_string_en->string_override) ? $obj_string_en->string_override : $obj_string_en->string_default);
}
// If we found any match
if (!empty($string)) {
$map[$string_id] = $string;
}
}
}
unset($obj_string_en);
unset($obj_string_loc);
unset($map_en);
unset($map_loc);
// Cache with tag (tag allows easy clean for multiple langs at once)
$cache->save($map, self::CACHE_TAG_TRANSLATIONS . '_' . $locale);
}
$translate = _DevblocksTranslationManager::getInstance();
$translate->addLocale($locale, $map);
$translate->setLocale($locale);
$languages[$locale] = $translate;
return $translate;
}