本文整理匯總了PHP中Languages::local方法的典型用法代碼示例。如果您正苦於以下問題:PHP Languages::local方法的具體用法?PHP Languages::local怎麽用?PHP Languages::local使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Languages
的用法示例。
在下文中一共展示了Languages::local方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: findOptions
/**
* Get language options for in desired language. Useful to build a Select widget.
*
* @param array|string|int $selected - An array of language codes to mark as selected
* @param array $pool (optional) - An array of language codes to be displayed. Leave null to show all.
* @param string $lang (optional) - Get language names for this language.
*
* @return array
*/
public static function findOptions($selected = array(), $pool = null, $lang = null)
{
if (!is_array($selected)) {
$selected = array($selected);
}
$native = Languages::all()->listAll('name');
if (is_array($pool)) {
$native = array_intersect_key($native, array_flip($pool));
}
if ($lang === null) {
$lang = Lang::get();
}
// try to get languages in author language
$local = Languages::local()->listAll($lang);
// if languages not found, use english ones
if ($local === false) {
$local = Languages::local()->listAll();
}
$options = array();
foreach ($native as $code => $info) {
$options[] = array($code, in_array($code, $selected), sprintf("[%s] %s%s", strtoupper($code), isset($local[$code]) ? $local[$code] . ' || ' : '', $info['name']));
}
return $options;
}
示例2: getAllLangs
public static function getAllLangs($lc = null)
{
if ($lc === null) {
$lc = self::getLangCode();
}
if (!($languages = Languages::local()->listAll($lc))) {
$languages = Languages::local()->listAll();
}
return $languages;
}